Zen API
 All Classes Files Functions Variables Typedefs Friends Macros Modules Pages
kAlloc.h
Go to the documentation of this file.
1 
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 #include <kApi/kAlloc.x.h>
16 
24 /*
25 * Public
26 */
27 
37 kInlineFx(kStatus) kAlloc_Get(kAlloc alloc, kSize size, void* mem)
38 {
39  return xkAlloc_VTable(alloc)->VGet(alloc, size, mem);
40 }
41 
51 kInlineFx(kStatus) kAlloc_GetZero(kAlloc alloc, kSize size, void* mem)
52 {
53  kCheck(kAlloc_Get(alloc, size, mem));
54 
55  kCheck(kMemSet(kPointer_ReadAs(mem, kPointer), 0, size));
56 
57  return kOK;
58 }
59 
69 kInlineFx(kStatus) kAlloc_GetObject(kAlloc alloc, kType type, void* mem)
70 {
71  return kAlloc_Get(alloc, kType_InnerSize(type), mem);
72 }
73 
82 kInlineFx(kStatus) kAlloc_Free(kAlloc alloc, void* mem)
83 {
84  return xkAlloc_VTable(alloc)->VFree(alloc, mem);
85 }
86 
96 {
97  kCheck(kAlloc_Free(alloc, *(void**)mem));
98 
100 
101  return kOK;
102 }
103 
114 {
115  return xkAlloc_Static()->appAlloc;
116 }
117 
130 {
131  return xkAlloc_Static()->systemAlloc;
132 }
133 
142 {
143  return kIsNull(alloc) ? kAlloc_App() : alloc;
144 }
145 
146 /*
147 * Protected
148 */
149 
161 kFx(kStatus) kAlloc_Init(kAlloc alloc, kType type, kAlloc allocator);
162 
171 kFx(kStatus) kAlloc_VRelease(kAlloc alloc);
172 
184 kFx(kStatus) kAlloc_VGet(kAlloc alloc, kSize size, void* mem);
185 
196 kFx(kStatus) kAlloc_VFree(kAlloc alloc, void* mem);
197 
198 #endif
kStatus kAlloc_VRelease(kAlloc alloc)
Protected virtual method that deallocates any resources owned by the object.
#define kPointer_WriteAs(POINTER, VALUE, TYPE)
Deferences a pointer, assuming the specified type, and assigns a value to the resulting reference...
Definition: kApiDef.h:329
kAlloc kAlloc_Fallback(kAlloc alloc)
Returns the passed allocator, or if null, the App allocator.
Definition: kAlloc.h:141
kStatus kAlloc_Init(kAlloc alloc, kType type, kAlloc allocator)
Protected method called by derived classes to initialize the kAlloc base class.
Represents a void pointer.
#define kIsNull(POINTER)
Tests for equality with null pointer.
Definition: kApiDef.h:339
kAlloc kAlloc_App()
Gets the allocator that should normally be used by applications to request memory.
Definition: kAlloc.h:113
Represents an unsigned integer that can store a pointer address.
Abstract base class for memory allocator types.
kStatus kAlloc_Free(kAlloc alloc, void *mem)
Frees a block of memory.
Definition: kAlloc.h:82
#define kCheck(EXPRESSION)
Executes a return statement if the given expression is not kOK.
Definition: kApiDef.h:559
kStatus kAlloc_GetObject(kAlloc alloc, kType type, void *mem)
Allocates a block of memory large enough for an object of the specified type.
Definition: kAlloc.h:69
#define kInlineFx(TYPE)
Inline method declaration helper.
Definition: kApiDef.h:26
kAlloc kAlloc_System()
Gets the system allocator.
Definition: kAlloc.h:129
Core Zen type declarations.
kStatus kAlloc_VGet(kAlloc alloc, kSize size, void *mem)
Protected virtual method that allocates memory.
kStatus kAlloc_FreeRef(kAlloc alloc, void *mem)
Frees a block of memory and sets the memory pointer to kNULL.
Definition: kAlloc.h:95
Represents metadata about a type (class, interface, or value).
kSize kType_InnerSize(kType type)
Gets the internal size of a type.
Definition: kType.h:321
kStatus kAlloc_VFree(kAlloc alloc, void *mem)
Protected virtual method that frees memory.
#define kOK
Operation successful.
Definition: kApiDef.h:513
Represents an error code.
#define kNULL
Null pointer.
Definition: kApiDef.h:267
#define kPointer_ReadAs(POINTER, TYPE)
Deferences a pointer, assuming the specified type, and returns the resulting value.
Definition: kApiDef.h:318
kStatus kAlloc_Get(kAlloc alloc, kSize size, void *mem)
Allocates a block of memory.
Definition: kAlloc.h:37
kStatus kAlloc_GetZero(kAlloc alloc, kSize size, void *mem)
Allocates a block of memory and zero-initializes the block.
Definition: kAlloc.h:51
kStatus kMemSet(void *dest, kByte fill, kSize size)
Sets a block of memory to the given byte value.