Zen API

- Home
- Help Topics
- Types by Category
- All Types
- Files

All Classes Files Functions Variables Typedefs Macros Groups Pages
kAlloc.h
Go to the documentation of this file.
1 /**
2 * @file kAlloc.h
3 * @brief Declares the kAlloc class.
4 *
5 * @internal
6 * Copyright (C) 2005-2014 by LMI Technologies Inc.
7 * Licensed under the MIT License.
8 * Redistributed files must retain the above copyright notice.
9 */
10 #include <kApi/kApiDef.h> //--inclusion order controlled by kApiDef
11
12 #ifndef K_API_ALLOC_H
13 #define K_API_ALLOC_H
14
15 kBeginHeader()
16
17 /**
18 * @class kAlloc
19 * @extends kObject
20 * @ingroup kApi
21 * @brief Abstract base class for memory allocator types.
22 */
23
24 /**
25 * Allocates a block of memory.
26 *
27 * @public @memberof kAlloc
28 * @param alloc Allocator object.
29 * @param size Size of memory to be allocated.
30 * @param mem Receives pointer to allocated memory.
31 * @return Operation status.
32 */
33 kFx(kStatus) kAlloc_Get(kAlloc alloc, kSize size, void* mem);
34
35 /**
36 * Allocates a block of memory and zero-initializes the block.
37 *
38 * @public @memberof kAlloc
39 * @param alloc Allocator object.
40 * @param size Size of memory to be allocated.
41 * @param mem Receives pointer to allocated memory.
42 * @return Operation status.
43 */
44 kFx(kStatus) kAlloc_GetZero(kAlloc alloc, kSize size, void* mem);
45
46 /**
47 * Frees a block of memory.
48 *
49 * @public @memberof kAlloc
50 * @param alloc Allocator object.
51 * @param mem Pointer to memory to be freed.
52 * @return Operation status.
53 */
54 kFx(kStatus) kAlloc_Free(kAlloc alloc, void* mem);
55
56 /**
57 * Frees a block of memory and sets the memory pointer to kNULL.
58 *
59 * @public @memberof kAlloc
60 * @param alloc Allocator object.
61 * @param mem Pointer to pointer to memory to be freed.
62 * @return Operation status.
63 */
64 kFx(kStatus) kAlloc_FreeRef(kAlloc alloc, void* mem);
65
66 /**
67 * Gets the allocator that should normally be used by applications to request memory.
68 *
69 * The App alloctor is typically implemented by layering additional allocators on the
70 * System allocator (e.g., kPoolAlloc, kDebugAlloc).
71 *
72 * @public @memberof kAlloc
73 * @return Application memory allocator.
74 */
75 kFx(kAlloc) kAlloc_App();
76
77 /**
78 * Gets the system allocator.
79 *
80 * The System allocator is a kUserAlloc instance that allocates directly from main system memory.
81 *
82 * For most purposes, the App allocator should be prefered to the System allocator. Use of the System
83 * allocator may be appropriate when the additional layers provided by the App allocator are undesirable.
84 *
85 * @public @memberof kAlloc
86 * @return System memory allocator.
87 */
88 kFx(kAlloc) kAlloc_System();
89
90 /**
91 * Returns the passed allocator, or if null, the App allocator.
92 *
93 * @public @memberof kAlloc
94 * @param alloc Allocator.
95 * @return Allocator.
96 */
97 kFx(kAlloc) kAlloc_Fallback(kAlloc alloc);
98
99 #define kAlloc_Get_(ALLOC, SIZE, MEM) kxAlloc_Get_(ALLOC, SIZE, MEM) ///< Macro version of kAlloc_Get
100 #define kAlloc_GetZero_(ALLOC, SIZE, MEM) kxAlloc_GetZero_(ALLOC, SIZE, MEM) ///< Macro version of kAlloc_GetZero
101 #define kAlloc_Free_(ALLOC, MEM) kxAlloc_Free_(ALLOC, MEM) ///< Macro version of kAlloc_Free
102 #define kAlloc_FreeRef_(ALLOC, MEM) kxAlloc_FreeRef_(ALLOC, MEM) ///< Macro version of kAlloc_FreeRef
103
104 #define kAlloc_App_() kxAlloc_App_() ///< Macro version of kAlloc_App
105 #define kAlloc_System_() kxAlloc_System_() ///< Macro version of kAlloc_System
106 #define kAlloc_Fallback_(ALLOC) kxAlloc_Fallback_(ALLOC) ///< Macro version of kAlloc_Fallback
107
108 kEndHeader()
109
110 #include <kApi/kAlloc.x.h>
111
112 #endif
kAlloc::kAlloc_App
kAlloc kAlloc_App()
Gets the allocator that should normally be used by applications to request memory.
kAlloc::kAlloc_FreeRef
kStatus kAlloc_FreeRef(kAlloc alloc, void *mem)
Frees a block of memory and sets the memory pointer to kNULL.
kAlloc::kAlloc_Fallback
kAlloc kAlloc_Fallback(kAlloc alloc)
Returns the passed allocator, or if null, the App allocator.
kSize
Represents an unsigned integer that can store a pointer address.
kAlloc
Abstract base class for memory allocator types.
kAlloc::kAlloc_Get
kStatus kAlloc_Get(kAlloc alloc, kSize size, void *mem)
Allocates a block of memory.
kApiDef.h
Essential API declarations.
kAlloc::kAlloc_GetZero
kStatus kAlloc_GetZero(kAlloc alloc, kSize size, void *mem)
Allocates a block of memory and zero-initializes the block.
kAlloc::kAlloc_Free
kStatus kAlloc_Free(kAlloc alloc, void *mem)
Frees a block of memory.
kStatus
Represents an enumeration of error codes.
kAlloc::kAlloc_System
kAlloc kAlloc_System()
Gets the system allocator.