1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_RTL_ALLOC_H
21 #define INCLUDED_RTL_ALLOC_H
23 #include <sal/config.h>
25 #include <sal/saldllapi.h>
26 #include <sal/types.h>
35 A call to this function will return NULL upon the requested
36 memory size being either zero or larger than currently allocatable.
38 @param Bytes [in] memory size.
39 @return pointer to allocated memory.
41 SAL_DLLPUBLIC
void * SAL_CALL
rtl_allocateMemory (
43 ) SAL_THROW_EXTERN_C();
46 /** Reallocate memory.
48 A call to this function with parameter 'Ptr' being NULL
49 is equivalent to a rtl_allocateMemory() call.
50 A call to this function with parameter 'Bytes' being 0
51 is equivalent to a rtl_freeMemory() call.
53 @see rtl_allocateMemory()
56 @param Ptr [in] pointer to previously allocated memory.
57 @param Bytes [in] new memory size.
58 @return pointer to reallocated memory. May differ from Ptr.
60 SAL_DLLPUBLIC
void * SAL_CALL
rtl_reallocateMemory (
63 ) SAL_THROW_EXTERN_C();
67 @param Ptr [in] pointer to previously allocated memory.
68 @return none. Memory is released. Ptr is invalid.
70 SAL_DLLPUBLIC
void SAL_CALL
rtl_freeMemory (
72 ) SAL_THROW_EXTERN_C();
75 /** Allocate and zero memory.
77 A call to this function will return NULL upon the requested
78 memory size being either zero or larger than currently allocatable.
80 @param Bytes [in] memory size.
81 @return pointer to allocated and zero'ed memory.
83 SAL_DLLPUBLIC
void * SAL_CALL
rtl_allocateZeroMemory (
85 ) SAL_THROW_EXTERN_C();
88 /** Zero and free memory.
89 @param Ptr [in] pointer to previously allocated memory.
90 @param Bytes [in] memory size.
91 @return none. Memory is zero'ed and released. Ptr is invalid.
93 SAL_DLLPUBLIC
void SAL_CALL
rtl_freeZeroMemory (
96 ) SAL_THROW_EXTERN_C();
99 /** Opaque rtl_arena_type.
101 typedef struct rtl_arena_st rtl_arena_type
;
103 #define RTL_ARENA_NAME_LENGTH 31
106 /** rtl_arena_create()
108 * @param pName [in] descriptive name; for debugging purposes.
109 * @param quantum [in] resource allocation unit / granularity; rounded up to next power of 2.
110 * @param quantum_cache_max [in] max resources to cache; rounded up to next multiple of quantum; usually 0.
111 * @param source_arena [in] passed as argument to source_alloc, source_free; usually NULL.
112 * @param source_alloc [in] function to allocate resources; usually rtl_arena_alloc.
113 * @param source_free [in] function to free resources; usually rtl_arena_free.
114 * @param nFlags [in] flags; usually 0.
116 * @return pointer to rtl_arena_type, or NULL upon failure.
118 * @see rtl_arena_destroy()
120 SAL_DLLPUBLIC rtl_arena_type
* SAL_CALL
rtl_arena_create (
123 sal_Size quantum_cache_max
,
124 rtl_arena_type
* source_arena
,
125 void * (SAL_CALL
* source_alloc
)(rtl_arena_type
*, sal_Size
*),
126 void (SAL_CALL
* source_free
) (rtl_arena_type
*, void *, sal_Size
),
128 ) SAL_THROW_EXTERN_C();
131 /** rtl_arena_destroy()
133 * @param pArena [in] the arena to destroy.
136 * @see rtl_arena_create()
138 SAL_DLLPUBLIC
void SAL_CALL
rtl_arena_destroy (
139 rtl_arena_type
* pArena
140 ) SAL_THROW_EXTERN_C();
143 /** rtl_arena_alloc()
145 * @param pArena [in] arena from which resource is allocated.
146 * @param pBytes [inout] size of resource to allocate.
148 * @return allocated resource, or NULL upon failure.
150 * @see rtl_arena_free()
152 SAL_DLLPUBLIC
void * SAL_CALL
rtl_arena_alloc (
153 rtl_arena_type
* pArena
,
155 ) SAL_THROW_EXTERN_C();
160 * @param pArena [in] arena from which resource was allocated.
161 * @param pAddr [in] resource to free.
162 * @param nBytes [in] size of resource.
166 * @see rtl_arena_alloc()
168 SAL_DLLPUBLIC
void SAL_CALL
rtl_arena_free (
169 rtl_arena_type
* pArena
,
172 ) SAL_THROW_EXTERN_C();
175 /** Opaque rtl_cache_type.
177 typedef struct rtl_cache_st rtl_cache_type
;
179 #define RTL_CACHE_NAME_LENGTH 31
181 #define RTL_CACHE_FLAG_BULKDESTROY 1
183 /** rtl_cache_create()
185 * @param pName [in] descriptive name; for debugging purposes.
186 * @param nObjSize [in] object size.
187 * @param nObjAlign [in] object alignment; usually 0 for suitable default.
188 * @param constructor [in] object constructor callback function; returning 1 for success or 0 for failure.
189 * @param destructor [in] object destructor callback function.
190 * @param reclaim [in] reclaim callback function.
191 * @param pUserArg [in] opaque argument passed to callback functions.
192 * @param pSource [in] opaque argument passed to callback functions.
193 * @param nFlags [in] flags.
195 * @return pointer to rtl_cache_type, or NULL upon failure.
197 * @see rtl_cache_destroy()
199 SAL_DLLPUBLIC rtl_cache_type
* SAL_CALL
rtl_cache_create (
203 int (SAL_CALL
* constructor
)(void * pObj
, void * pUserArg
),
204 void (SAL_CALL
* destructor
) (void * pObj
, void * pUserArg
),
205 void (SAL_CALL
* reclaim
) (void * pUserArg
),
207 rtl_arena_type
* pSource
,
209 ) SAL_THROW_EXTERN_C();
212 /** rtl_cache_destroy()
214 * @param pCache [in] the cache to destroy.
218 * @see rtl_cache_create()
220 SAL_DLLPUBLIC
void SAL_CALL
rtl_cache_destroy (
221 rtl_cache_type
* pCache
222 ) SAL_THROW_EXTERN_C();
225 /** rtl_cache_alloc()
227 * @param pCache [in] cache from which object is allocated.
229 * @return pointer to allocated object, or NULL upon failure.
231 SAL_DLLPUBLIC
void * SAL_CALL
rtl_cache_alloc (
232 rtl_cache_type
* pCache
233 ) SAL_THROW_EXTERN_C();
238 * @param pCache [in] cache from which object was allocated.
239 * @param pObj [in] object to free.
243 * @see rtl_cache_alloc()
245 SAL_DLLPUBLIC
void SAL_CALL
rtl_cache_free (
246 rtl_cache_type
* pCache
,
248 ) SAL_THROW_EXTERN_C();
255 #endif // INCLUDED_RTL_ALLOC_H
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */