Posts

Showing posts with the label programming

What is memory leak ?

Image
What is memory leak ? wiki said: A  memory leak  or  leakage  in  computer science  is a particular type of memory consumption by a  computer program  where the program is unable to release  memory  it has acquired. more detail in : http://en.wikipedia.org/wiki/Memory_leak an easy understand example about memory leak, please refer to this link: 女工程師的美加生活手札-  Memory Leak   other related webpage : Handling memory leaks in Java programs Memory Leak Detection in C++ 基本避免Memory Leak的技巧 — garylee

MinGW 與 Cygwin 的不同處

Image
MinGW 可以唸做 Min-G-W「明~碁~大不了~」 或是MinG-W「名~大不了~」, 也有人唸做 ming-wee「名貴(台語發音)」 或是 min gnu 「明~格奴」。 可參考 http://en.wikipedia.org/wiki/MinGW MinGW 原來是 Cygwin (念做「賽葛-wing」)裡 GNU 開發工具的一個分支,沒 Cygwin 複雜,而且目的也與 Cygwin 不同。 Cygwin 的目的是希望透過一個 dll (就是 Cygwin1.dll 通常被安裝在 C:\Windows\system32底下) 建立一個系統呼叫轉換層,將原先 unix 世界裡的 system call 呼叫,經由這個 DLL 把它們映對到微軟視窗作業系統的系統呼叫,如此一來就可以很方便在 Windows 底下模擬出一個 unix 平台來,這樣你不需要一個 unix 機器照樣也可以開發 unix 程式。 開發好的程式只要拿到 UNIX 平台上就可以使用。同理原來UNIX上諸多 Open source 程式也可以粉方便拿到 Windows 世界來享用, 當然啦!UNIX system calls 與 Windows APIs 不盡然可以一對一對應,Cygwin 的目標在於儘可能 Compatible,執行績效倒不是重點考量。

什麼是 Function Pointer ?

Image
函式指標變數(Function Pointer)就是可以存放函式起始位址的變數。 使用方式: double (*fp)(double); ... fp = square; ... (*fp)(x); // 呼叫 square() 函式 以下轉載自 C程式語言教學 C語言允許陣列指標和函數三者混合宣告,以表達複雜的資料結構。對於要撰寫比較複雜的應用程式來說,了解這三者的關係是非常必要的。例如下面的變數x到底是甚麼? char (*x[])(); 要看懂這些東西,首先要查型別與運算裡有關優先權與結合序的表格,得到()[]是第一優先權左結合,而*是第二優先權右結合。在看變數宣告時,如同運算式的推演過程,必須遵守C程式語言對*()[]的優先權定義。接下來請讀者背誦下面的口訣 * 看見[]就說array[] of * 看見*就說pointer to * 看見變數後面的()就說function() returning 上述口訣配合*()[]的優先權,依序找出其執行的順序,每看到運算符號就把這幾句口訣念出來。因此變數的意義如下面範例 char *x; // x: a pointer to char char x[3]; // x: an array[3] of char char x(); // x: a function() returning char char *x[3]; // x: an array[3] of pointer to char char (*x)[3]; // x: a pointer to array[3] of char char **x; // x: a pointer to pointer to char char *x(); // x: a function() returning pointer to char char *x()[3]; // x: a function() returning array[3] of pointer to char char (*x[])(); // x: an array[] of pointer to function() returning char char (...

簡介C的資料型態

C has really only four types of variables: 1. char 2. int 3. float 4. double Keyword Variable Type Range char Character (or string) -128 to 127 (1 byte) int Integer -32,768 to 32,767 (4 byte) short Short integer -32,768 to 32,767 (4 byte) short int Short integer -32,768 to 32,767 (4 byte) long Long integer -2,147,483,648 to 2,147,483,647 unsigned char Unsigned character 0 to 255 unsigned int Unsigned integer 0 to 65,535 unsigned short Unsigned short integer 0 to 65,535 unsigned long Unsigned long integer 0 to 4,294,967,295 float Single-precision +/-3.4E10^38 to +/-3.4E10^38 floating-point (accurate to 7 digits) double Double-precision +/-1.7E10^308 to +/-1.7E10^308 floating-point (accurate to 15 digits) -- Pointer is the address in thememory...

extern 與 extern "C"

Image
整理一下看網友blog的文章筆記: 關於 extern : 1. 在function外定義的變數就叫外部變數,相反的在function內就叫內部變數。 2. 外部變數的視野是從定義的開始那行到本身檔案結束的最後一行(此稱自然視野)。 3. 若外在變數要被其他的檔案所用,那就要在別的檔案那裡宣告extern,以表它定義在別的檔上(此稱視野擴展)。 1. extern的用法 想用外部變數的時候,在變數前面前面加extern。 2. C++ extern 全域變數正確用法 提到應該在.h檔內宣告變數為全域變數, extern int i; 但是還要在cpp檔中重新定義一次。 int i; 要注意的是一定要配合.h檔,在相同名稱的.cpp內重新定義,不然會出現linker error。 也可以這樣用, -- 關於 extern "C" {} extern "C"的用法 c 語言static與extern的用法

Memory Allocation

Memory Allocation : "g_new() #define g_new(struct_type, n_structs) Allocates n_structs elements of type struct_type. The returned pointer is cast to a pointer to the given type. If n_structs is 0 it returns NULL. Since the returned pointer is already casted to the right type, it is normally unnecessary to cast it explicitly, and doing so might hide memory allocation errors. struct_type : the type of the elements to allocate n_structs : the number of elements to allocate Returns : a pointer to the allocated memory, cast to a pointer to struct_type g_new0() #define g_new0(struct_type, n_structs) Allocates n_structs elements of type struct_type, initialized to 0's. The returned pointer is cast to a pointer to the given type. If n_structs is 0 it returns NULL. Since the returned pointer is already casted to the right type, it is normally unnecessary to cast it explicitly, and doing so might hide memory allocation errors. struct_type : the type of the el...

Doubly-Linked Lists

Doubly-Linked Lists : "GList typedef struct { gpointer data; GList *next; GList *prev; } GList; The GList struct is used for each element in a doubly-linked list. gpointer data; holds the element's data, which can be a pointer to any kind of data, or any integer value using the Type Conversion Macros. GList *next; contains the link to the next element in the list. GList *prev; contains the link to the previous element in the list."

Spawning Processes

Spawning Processes : "g_spawn_async_with_pipes () gboolean g_spawn_async_with_pipes (const gchar *working_directory, gchar **argv, gchar **envp, GSpawnFlags flags, GSpawnChildSetupFunc child_setup, gpointer user_data, GPid *child_pid, gint *standard_input, gint *standard_output,"

Shell-related Utilities

Shell-related Utilities : "g_shell_parse_argv () gboolean g_shell_parse_argv (const gchar *command_line, gint *argcp, gchar ***argvp, GError **error); Parses a command line into an argument vector, in much the same way the shell would, but without many of the expansions the shell would perform (variable expansion, globs, operators, filename expansion, etc. are not supported). The results are defined to be the same as those you would get from a UNIX98 /bin/sh, as long as the input contains none of the unsupported shell expansions. If the input does contain such expansions, they are passed through literally. Possible errors are those from the G_SHELL_ERROR domain. Free the returned vector with g_strfreev(). command_line : command line to parse argcp : return location for number of args...

Memory Allocation

Memory Allocation : "g_new0() #define g_new0(struct_type, n_structs) Allocates n_structs elements of type struct_type, initialized to 0's. The returned pointer is cast to a pointer to the given type. If n_structs is 0 it returns NULL. Since the returned pointer is already casted to the right type, it is normally unnecessary to cast it explicitly, and doing so might hide memory allocation errors. struct_type : the type of the elements to allocate. n_structs : the number of elements to allocate. Returns : a pointer to the allocated memory, cast to a pointer to struct_type."

好用的sprintf

sprintf - C++ Reference 但今天要介紹的是 g_sprintf 以及 g_strdup_printf g_sprintf () gint g_sprintf (gchar *string, gchar const *format, ...); An implementation of the standard sprintf() function which supports positional parameters, as specified in the Single Unix Specification. g_strdup_printf () gchar* g_strdup_printf (const gchar *format ...); Similar to the standard C sprintf() function but safer, since it calculates the maximum space required and allocates memory to hold the result. The returned string should be freed when no longer needed.

java script 對話方式

Image
java script 對話方式 alert("message") 顯示含有給定message的"JavaScript Alert"對話框。 confirm("message") 顯示含有給定message的"Confirm"對話方塊(有一個OK按鈕和一個Cancel按鈕)。如果User單擊OK返回true,否則返回false。 prompt("message") 顯示一個"prompt"對話方塊,要求User根據顯示message給予相應輸入。 open("URL","name") 打開一個新視窗,給予一個指定的名字。 close() 關閉當前視窗。 window的open( )就是 JavaScript 程式裡面用來開新視窗的方法, 呼叫的基本格式是: winid=window.open("URL"); winid=window.open(" "); 開啟空白的瀏覽視窗 window.open("URL"); 不記錄被開啟之瀏覽視窗的 id winid=window.open("HTML檔案"); HTML檔案的角色就相當於URL 特別值得注意的是傳回值 winid(window id), 有了這個winid,我們將來可以呼叫, winid.close( ); 來關閉此一瀏覽視窗。 好吧,我覺得我命了很糟糕的標題。

GtkTreeModel 解釋

GtkTreeModel GtkTreeModel : "One can convert a path to an iterator by calling gtk_tree_model_get_iter(). These iterators are the primary way of accessing a model and are similar to the iterators used by GtkTextBuffer. They are generally statically allocated on the stack and only used for a short time. The model interface defines a set of operations using them for navigating the model."

GTK 如何傳遞signal ?

Image
GTK 如何傳遞signal  ? GTK透過GDK來處理事件,GDK會將每個接受到的XEvent轉換為GdkEvent,然後傳播給GtkWidget,引發一個與事件相對應的事件Signal,再透過Callback函式處理事件。 from 良葛格GTK學習筆記  GDK 事件結構 In the X Window System core protocol, only four kinds of packets are sent, asynchronously, over the network: requests, replies, events, and errors. from wiki : X Window System core protocol Xlib is an X Window System protocol client library in the C programming language. It contains functions for interacting with an X server. These functions allow programmers to write programs without knowing the details of the protocol. from wiki : Xlib 還不太能講清楚說明白的東西 @@ 先暫存一下 持續補筆記

很好很強大的JQuery

Image
JQuery 越來越紅,現在最新版本是 1.2.6 , 最近新聞是 jQuery, Microsoft 及 Nokia 的合作 ! 已經不只是一個社群,因為功能很強大而逐漸被業界採納。 新手入門個人推薦ericsk大寫的 jQuery 學習心得筆記 系列文。 好多東西要學呀 @@ -- 相關連結: 維基 JQuery 中文 JQuery tw google group JQuery 台灣 javaworld@tw 網友qrtt1 寫的 jQuery 入門

GTK中對於Key Values的解釋

GTK中對於Key Values的解釋 Key Values : "gdk_keymap_get_entries_for_keyval () gboolean gdk_keymap_get_entries_for_keyval (GdkKeymap *keymap, guint keyval, GdkKeymapKey **keys, gint *n_keys); Obtains a list of keycode/group/level combinations that will generate keyval. Groups and levels are two kinds of keyboard mode; in general, the level determines whether the top or bottom symbol on a key is used, and the group determines whether the left or right symbol is used. On US keyboards, the shift key changes the keyboard level, and there are no groups. A group switch key might convert a keyboard between Hebrew to English modes, for example. GdkEventKey contains a group field that indicates the active keyboard group. The level is computed from the modifier mask. The returned array should be freed with g_free(). keymap : a GdkKeymap, or NULL to use the default keymap keyval : a keyval, such as GDK_a, GDK_Up, GDK_Return, etc. keys : return location for an array of GdkKeymapKey n_...

方便好用的makefile ~

Image
makefile也是個很神奇的東西阿 先看一下 官方介紹 GNU `make' http://www.gnu.org/software/make/manual/make.html 再來看一下維基怎麼說 wiki make http://en.wikipedia.org/wiki/Make_%28software%29 另外還有一個與gtk相關的makefile指導 http://bo.majewski.name/bluear/gnu/GTK/plain/index.htm 真的有很多東西要學阿 !

常用gcc指令說明

Image
常用gcc(GNU Compiler Collection)指令說明 設定編譯出的 object 檔檔名或是可執行檔檔名-o 參數: -o out_put_filename 在編譯過程做最佳化-O 參數: -O 設定搜尋標頭檔目錄-I 參數: -Idir_name 設定搜尋程式庫目錄-L 參數: -Ldir_name 設定程式庫檔案-l 參數: -lname 提供進一步的資訊 以便使用者找尋程式中的錯誤-Wall 參數: -Wall 在編譯出可執行檔時,附加執行時除錯資訊, 以供 gdb 讀取 (若要使用 ABSoft 的除錯程式,則須將參數改為 -gdwarf )-g 參數: -g 更多的說明 man gcc info gcc 參考資料 wiki GCC http://en.wikipedia.org/wiki/GNU_Compiler_Collection

什麼是callback function ?

Image
In computer programming, a callback is executable code that is passed as an argument to other code. It allows a lower-level software layer to call a subroutine (or function) defined in a higher-level layer. 所謂callback function就是等著被呼叫的function 通常會使用在interrupt handler(中斷處理), 或一些event handler(事件處理) 這些callback function一般會在你的主程式向系統註冊它們的address 當某些硬體或軟體中斷髮生時, 或某些事件發生時 系統就會去呼叫這些callback function 所以, callback function並不是直接讓你的程式呼叫的~ 如果沒有使用callback function的機制, 而需要在某些事件發生時去做一些事 就變成要有一個迴圈一直去監視事件是否發生, 這就會很耗損CPU時間 在Windows的AP或driver很常見到Callback function的使用比如說, timer也是一個callback function~ 而 gtk 中 event loop 的概念也需要 callback function 來實現 ! 參考資料 事件驅動程式設計 http://tinyurl.com/28mdag wiki : Callback (computer science)

搜尋

Agoda

熱門文章

[社會觀察] 一生順遂與命途乖舛

新鮮人找工作:職場名詞解釋 AE FAE Pre-sales Post-sales

日本旅行 去東京可以在哪邊買羽球相關用品?WEMBLEY/WINDSOR/梭家/Victoria/Alpen TOKYO/

中華民國2024 總統、副總統選舉公告發布 連署參選門檻28萬9667人 可以推薦候選人的政黨包括民進黨、國民黨、民眾黨和時力

什麼是 OTA ?

[FAANG面試] 如何準備Google Technical Program Manager (TPM) 面試

[HMD Global] Nokia 2020 新手機發布 首款 5G 手機 Nokia 8.3 預計夏季開賣 !

關於中國:202X年

[表特][Passion Sisters] 中信兄弟PS女孩 浮誇甜心 凱蒂 炸裂全場~ 小許瑋甯

[音樂] 霖霖 新單曲:給你了