1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: alloc.h,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
34 # include <sal/types.h>
42 @descr A call to this function will return NULL upon the requested
43 memory size being either zero or larger than currently allocatable.
45 @param Bytes [in] memory size.
46 @return pointer to allocated memory.
48 void * SAL_CALL
rtl_allocateMemory (
50 ) SAL_THROW_EXTERN_C();
53 /** Reallocate memory.
54 @descr A call to this function with parameter 'Ptr' being NULL
55 is equivalent to a rtl_allocateMemory() call.
57 A call to this function with parameter 'Bytes' being 0
58 is equivalent to a rtl_freeMemory() call.
60 @see rtl_allocateMemory()
63 @param Ptr [in] pointer to previously allocated memory.
64 @param Bytes [in] new memory size.
65 @return pointer to reallocated memory. May differ from Ptr.
67 void * SAL_CALL
rtl_reallocateMemory (
70 ) SAL_THROW_EXTERN_C();
74 @param Ptr [in] pointer to previously allocated memory.
75 @return none. Memory is released. Ptr is invalid.
77 void SAL_CALL
rtl_freeMemory (
79 ) SAL_THROW_EXTERN_C();
82 /** Allocate and zero memory.
83 @descr A call to this function will return NULL upon the requested
84 memory size being either zero or larger than currently allocatable.
86 @param Bytes [in] memory size.
87 @return pointer to allocated and zero'ed memory.
89 void * SAL_CALL
rtl_allocateZeroMemory (
91 ) SAL_THROW_EXTERN_C();
94 /** Zero and free memory.
95 @param Ptr [in] pointer to previously allocated memory.
96 @param Bytes [in] memory size.
97 @return none. Memory is zero'ed and released. Ptr is invalid.
99 void SAL_CALL
rtl_freeZeroMemory (
102 ) SAL_THROW_EXTERN_C();
105 /** Opaque rtl_arena_type.
107 typedef struct rtl_arena_st rtl_arena_type
;
109 #define RTL_ARENA_NAME_LENGTH 31
112 /** rtl_arena_create()
114 * @param pName [in] descriptive name; for debugging purposes.
115 * @param quantum [in] resource allocation unit / granularity; rounded up to next power of 2.
116 * @param quantum_cache_max [in] max resources to cache; rounded up to next multiple of quantum; usually 0.
117 * @param source_arena [in] passed as argument to source_alloc, source_free; usually NULL.
118 * @param source_alloc [in] function to allocate resources; usually rtl_arena_alloc.
119 * @param source_free [in] function to free resources; usually rtl_arena_free.
120 * @param nFlags [in] flags; usually 0.
122 * @return pointer to rtl_arena_type, or NULL upon failure.
124 * @see rtl_arena_destroy()
127 SAL_CALL
rtl_arena_create (
130 sal_Size quantum_cache_max
,
131 rtl_arena_type
* source_arena
,
132 void * (SAL_CALL
* source_alloc
)(rtl_arena_type
*, sal_Size
*),
133 void (SAL_CALL
* source_free
) (rtl_arena_type
*, void *, sal_Size
),
135 ) SAL_THROW_EXTERN_C();
138 /** rtl_arena_destroy()
140 * @param pArena [in] the arena to destroy.
143 * @see rtl_arena_create()
146 SAL_CALL
rtl_arena_destroy (
147 rtl_arena_type
* pArena
148 ) SAL_THROW_EXTERN_C();
151 /** rtl_arena_alloc()
153 * @param pArena [in] arena from which resource is allocated.
154 * @param pBytes [inout] size of resource to allocate.
156 * @return allocated resource, or NULL upon failure.
158 * @see rtl_arena_free()
161 SAL_CALL
rtl_arena_alloc (
162 rtl_arena_type
* pArena
,
164 ) SAL_THROW_EXTERN_C();
169 * @param pArena [in] arena from which resource was allocated.
170 * @param pAddr [in] resource to free.
171 * @param nBytes [in] size of resource.
175 * @see rtl_arena_alloc()
178 SAL_CALL
rtl_arena_free (
179 rtl_arena_type
* pArena
,
182 ) SAL_THROW_EXTERN_C();
185 /** Opaque rtl_cache_type.
187 typedef struct rtl_cache_st rtl_cache_type
;
189 #define RTL_CACHE_NAME_LENGTH 31
191 #define RTL_CACHE_FLAG_BULKDESTROY 1
193 /** rtl_cache_create()
195 * @param pName [in] descriptive name; for debugging purposes.
196 * @param nObjSize [in] object size.
197 * @param nObjAlign [in] object alignment; usually 0 for suitable default.
198 * @param constructor [in] object constructor callback function; returning 1 for success or 0 for failure.
199 * @param destructor [in] object destructor callback function.
200 * @param reclaim [in] reclaim callback function.
201 * @param pUserArg [in] opaque argument passed to callback functions.
202 * @param nFlags [in] flags.
204 * @return pointer to rtl_cache_type, or NULL upon failure.
206 * @see rtl_cache_destroy()
209 SAL_CALL
rtl_cache_create (
213 int (SAL_CALL
* constructor
)(void * pObj
, void * pUserArg
),
214 void (SAL_CALL
* destructor
) (void * pObj
, void * pUserArg
),
215 void (SAL_CALL
* reclaim
) (void * pUserArg
),
217 rtl_arena_type
* pSource
,
219 ) SAL_THROW_EXTERN_C();
222 /** rtl_cache_destroy()
224 * @param pCache [in] the cache to destroy.
228 * @see rtl_cache_create()
231 SAL_CALL
rtl_cache_destroy (
232 rtl_cache_type
* pCache
233 ) SAL_THROW_EXTERN_C();
236 /** rtl_cache_alloc()
238 * @param pCache [in] cache from which object is allocated.
240 * @return pointer to allocated object, or NULL upon failure.
243 SAL_CALL
rtl_cache_alloc (
244 rtl_cache_type
* pCache
245 ) SAL_THROW_EXTERN_C();
250 * @param pCache [in] cache from which object was allocated.
251 * @param pObj [in] object to free.
255 * @see rtl_cache_alloc()
258 SAL_CALL
rtl_cache_free (
259 rtl_cache_type
* pCache
,
261 ) SAL_THROW_EXTERN_C();
268 #endif /*_RTL_ALLOC_H_ */