1// included by glib2.pas
2
3{$IFDEF read_forward_definitions}
4{$ENDIF read_forward_definitions}
5
6//------------------------------------------------------------------------------
7
8{$IFDEF read_interface_types}
9   PGMemVTable = ^TGMemVTable;
10   TGMemVTable = record
11        malloc : function (n_bytes:gsize):gpointer; cdecl;
12        realloc : function (mem:gpointer; n_bytes:gsize):gpointer; cdecl;
13        free : procedure (mem:gpointer); cdecl;
14        calloc : function (n_blocks:gsize; n_block_bytes:gsize):gpointer; cdecl;
15        try_malloc : function (n_bytes:gsize):gpointer; cdecl;
16        try_realloc : function (mem:gpointer; n_bytes:gsize):gpointer; cdecl;
17     end;
18
19   PGMemChunk = pointer; // internal structure of gmem.c
20   PGAllocator = pointer; // internal structure of gmem.c
21{$ENDIF read_interface_types}
22
23//------------------------------------------------------------------------------
24
25{$IFDEF read_interface_rest}
26const
27   G_MEM_ALIGN = GLIB_SIZEOF_VOID_P;
28
29{ Memory allocation functions }
30
31function g_malloc(n_bytes:gulong):gpointer; cdecl; external gliblib;
32function g_malloc0(n_bytes:gulong):gpointer; cdecl; external gliblib;
33function g_realloc(mem:gpointer; n_bytes:gulong):gpointer; cdecl; external gliblib;
34procedure g_free(mem:gpointer); cdecl; external gliblib;
35function g_try_malloc(n_bytes:gulong):gpointer; cdecl; external gliblib;
36function g_try_realloc(mem:gpointer; n_bytes:gulong):gpointer; cdecl; external gliblib;
37
38{ Convenience memory allocators }
39function g_new(bytes_per_struct, n_structs: gsize): gpointer;
40function g_new0(bytes_per_struct, n_structs: gsize): gpointer;
41function g_renew(struct_size: gsize; OldMem: gpointer; n_structs : gsize) : gpointer;
42
43{ Memory allocation virtualization for debugging purposes
44   g_mem_set_vtable() has to be the very first GLib function called
45   if being used
46  }
47{ optional  }
48
49procedure g_mem_set_vtable(vtable:PGMemVTable); cdecl; external gliblib;
50function g_mem_is_system_malloc:gboolean; cdecl; external gliblib;
51
52{$IFNDEF KYLIX}
53{ Memory profiler and checker, has to be enabled via g_mem_set_vtable() }
54var
55  {$IFDEF WINDOWS}
56  glib_mem_profiler_table : PGMemVTable; external gliblib name 'glib_mem_profiler_table';
57  {$ELSE}
58  glib_mem_profiler_table : PGMemVTable;cvar;external;
59  {$ENDIF}
60{$ENDIF}
61
62procedure g_mem_profile; cdecl; external gliblib;
63{ Memchunk convenience functions }
64
65{ c specific:
66 #define g_mem_chunk_create(type, pre_alloc, alloc_type)        (
67   g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")",
68                   sizeof (type), sizeof (type) * (pre_alloc), (alloc_type)) ) }
69
70function g_chunk_new(chunk : Pointer) : Pointer;
71function g_chunk_new0(chunk : Pointer) : Pointer;
72procedure g_chunk_free(mem_chunk:PGMemChunk; mem:gpointer);
73{ "g_mem_chunk_new" creates a new memory chunk.
74   Memory chunks are used to allocate pieces of memory which are
75    always the same size. Lists are a good example of such a data type.
76   The memory chunk allocates and frees blocks of memory as needed.
77    Just be sure to call "g_mem_chunk_free" and not "g_free" on data
78    allocated in a mem chunk. ("g_free" will most likely cause a seg
79    fault...somewhere).
80
81   Oh yeah, GMemChunk is an opaque data type. (You don't really
82    want to know what's going on inside do you?)
83  }
84{ ALLOC_ONLY MemChunk's can only allocate memory. The free operation
85    is interpreted as a no op. ALLOC_ONLY MemChunk's save 4 bytes per
86    atom. (They are also useful for lists which use MemChunk to allocate
87    memory but are also part of the MemChunk implementation).
88   ALLOC_AND_FREE MemChunk's can allocate and free memory.
89  }
90
91const
92   G_ALLOC_ONLY = 1;
93   G_ALLOC_AND_FREE = 2;
94
95function g_mem_chunk_new(name:Pgchar; atom_size:gint; area_size:gulong; _type:gint):PGMemChunk; cdecl; external gliblib;
96procedure g_mem_chunk_destroy(mem_chunk:PGMemChunk); cdecl; external gliblib;
97function g_mem_chunk_alloc(mem_chunk:PGMemChunk):gpointer; cdecl; external gliblib;
98function g_mem_chunk_alloc0(mem_chunk:PGMemChunk):gpointer; cdecl; external gliblib;
99procedure g_mem_chunk_free(mem_chunk:PGMemChunk; mem:gpointer); cdecl; external gliblib;
100procedure g_mem_chunk_clean(mem_chunk:PGMemChunk); cdecl; external gliblib;
101procedure g_mem_chunk_reset(mem_chunk:PGMemChunk); cdecl; external gliblib;
102procedure g_mem_chunk_print(mem_chunk:PGMemChunk); cdecl; external gliblib;
103procedure g_mem_chunk_info; cdecl; external gliblib;
104
105{ Ah yes...we have a "g_blow_chunks" function.
106   "g_blow_chunks" simply compresses all the chunks. This operation
107    consists of freeing every memory area that should be freed (but
108    which we haven't gotten around to doing yet). And, no,
109    "g_blow_chunks" doesn't follow the naming scheme, but it is a
110    much better name than "g_mem_chunk_clean_all" or something
111    similar.
112  }
113procedure g_blow_chunks; cdecl; external gliblib;
114
115{ Generic allocators }
116function g_allocator_new(name:Pgchar; n_preallocs:guint):PGAllocator; cdecl; external gliblib;
117procedure g_allocator_free(allocator:PGAllocator); cdecl; external gliblib;
118
119{ internal  }
120const
121   G_ALLOCATOR_LIST = 1;
122   G_ALLOCATOR_SLIST = 2;
123   G_ALLOCATOR_NODE = 3;
124
125{$ENDIF read_interface_rest}
126// included by glib2.pas
127
128