Zen API

- Home
- Topics
- Types
- Files

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 kCheckArgs(kAlloc_CanGetObject(alloc));
72
73 return kAlloc_Get(alloc, kType_InnerSize(type), mem);
74 }
75
84 kInlineFx(kStatus) kAlloc_Free(kAlloc alloc, void* mem)
85 {
86 return xkAlloc_VTable(alloc)->VFree(alloc, mem);
87 }
88
97 kInlineFx(kStatus) kAlloc_FreeRef(kAlloc alloc, void* mem)
98 {
99 kCheck(kAlloc_Free(alloc, *(void**)mem));
100
101 kPointer_WriteAs(mem, kNULL, kPointer);
102
103 return kOK;
104 }
105
116 kInlineFx(kStatus) kAlloc_Export(kAlloc alloc, void* dest, const void* src, kSize size)
117 {
118 return xkAlloc_VTable(alloc)->VExport(alloc, dest, src, size);
119 }
120
128 kInlineFx(kBool) kAlloc_CanGetObject(kAlloc alloc)
129 {
130 kObj(kAlloc, alloc);
131
132 return obj->canGetObject;
133 }
134
142 kInlineFx(kBool) kAlloc_IsForeign(kAlloc alloc)
143 {
144 kObj(kAlloc, alloc);
145
146 return obj->isForeign;
147 }
148
149
159 kInlineFx(kAlloc) kAlloc_App()
160 {
161 return xkAlloc_Static()->appAlloc;
162 }
163
175 kInlineFx(kAlloc) kAlloc_System()
176 {
177 return xkAlloc_Static()->systemAlloc;
178 }
179
187 kInlineFx(kAlloc) kAlloc_Fallback(kAlloc alloc)
188 {
189 return kIsNull(alloc) ? kAlloc_App() : alloc;
190 }
191
192 /*
193 * Protected
194 */
195
207 kFx(kStatus) kAlloc_Init(kAlloc alloc, kType type, kAlloc allocator);
208
217 kFx(kStatus) kAlloc_VRelease(kAlloc alloc);
218
230 kFx(kStatus) kAlloc_VGet(kAlloc alloc, kSize size, void* mem);
231
242 kFx(kStatus) kAlloc_VFree(kAlloc alloc, void* mem);
243
254 kFx(kStatus) kAlloc_VExport(kAlloc alloc, void* dest, const void* src, kSize size);
255
256 #endif
kAlloc::kAlloc_VRelease
kStatus kAlloc_VRelease(kAlloc alloc)
Protected virtual method that deallocates any resources owned by the object.
kPointer::kPointer_WriteAs
#define kPointer_WriteAs(POINTER, VALUE, TYPE)
Deferences a pointer, assuming the specified type, and assigns a value to the resulting reference...
Definition: kApiDef.h:331
kAlloc::kAlloc_Fallback
kAlloc kAlloc_Fallback(kAlloc alloc)
Returns the passed allocator, or if null, the App allocator.
Definition: kAlloc.h:187
kAlloc::kAlloc_Init
kStatus kAlloc_Init(kAlloc alloc, kType type, kAlloc allocator)
Protected method called by derived classes to initialize the kAlloc base class.
kPointer
Represents a void pointer.
kPointer::kIsNull
#define kIsNull(POINTER)
Tests for equality with null pointer.
Definition: kApiDef.h:341
kAlloc::kAlloc_App
kAlloc kAlloc_App()
Gets the allocator that should normally be used by applications to request memory.
Definition: kAlloc.h:159
kSize
Represents an unsigned integer that can store a pointer address.
kAlloc
Abstract base class for memory allocator types.
kAlloc::kAlloc_CanGetObject
kBool kAlloc_CanGetObject(kAlloc alloc)
Reports whether this allocator is suitable for allocating objects.
Definition: kAlloc.h:128
kAlloc::kAlloc_Free
kStatus kAlloc_Free(kAlloc alloc, void *mem)
Frees a block of memory.
Definition: kAlloc.h:84
kCheck
#define kCheck(EXPRESSION)
Executes a return statement if the given expression is not kOK.
Definition: kApiDef.h:561
kAlloc::kAlloc_GetObject
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
kInlineFx
#define kInlineFx(TYPE)
Inline method declaration helper.
Definition: kApiDef.h:26
kAlloc::kAlloc_System
kAlloc kAlloc_System()
Gets the system allocator.
Definition: kAlloc.h:175
kAlloc::kAlloc_Export
kStatus kAlloc_Export(kAlloc alloc, void *dest, const void *src, kSize size)
Copies memory from the allocator's address space to the host address space.
Definition: kAlloc.h:116
kObj
#define kObj(TypeName_T, T_object)
Declares a local "obj" (this-pointer) variable and initializes it from a type-checked object handle...
Definition: kApiDef.h:2923
kApiDef.h
Core Zen type declarations.
kAlloc::kAlloc_VGet
kStatus kAlloc_VGet(kAlloc alloc, kSize size, void *mem)
Protected virtual method that allocates memory.
kCheckArgs
#define kCheckArgs(EXPRESSION)
Executes a return statement if the given expression is not kTRUE.
Definition: kApiDef.h:584
kAlloc::kAlloc_FreeRef
kStatus kAlloc_FreeRef(kAlloc alloc, void *mem)
Frees a block of memory and sets the memory pointer to kNULL.
Definition: kAlloc.h:97
kAlloc::kAlloc_IsForeign
kBool kAlloc_IsForeign(kAlloc alloc)
Reports whether memory will be allocated in a foreign address space.
Definition: kAlloc.h:142
kType
Represents metadata about a type (class, interface, or value).
kType::kType_InnerSize
kSize kType_InnerSize(kType type)
Gets the internal size of a type.
Definition: kType.h:321
kAlloc::kAlloc_VFree
kStatus kAlloc_VFree(kAlloc alloc, void *mem)
Protected virtual method that frees memory.
kStatus::kOK
#define kOK
Operation successful.
Definition: kApiDef.h:515
kStatus
Represents an error code.
kNULL
#define kNULL
Null pointer.
Definition: kApiDef.h:269
kPointer::kPointer_ReadAs
#define kPointer_ReadAs(POINTER, TYPE)
Deferences a pointer, assuming the specified type, and returns the resulting value.
Definition: kApiDef.h:320
kAlloc::kAlloc_Get
kStatus kAlloc_Get(kAlloc alloc, kSize size, void *mem)
Allocates a block of memory.
Definition: kAlloc.h:37
kAlloc::kAlloc_VExport
kStatus kAlloc_VExport(kAlloc alloc, void *dest, const void *src, kSize size)
Protected virtual method that copies memory from the allocator's address space to the host address sp...
kBool
Represents a boolean value.
kAlloc::kAlloc_GetZero
kStatus kAlloc_GetZero(kAlloc alloc, kSize size, void *mem)
Allocates a block of memory and zero-initializes the block.
Definition: kAlloc.h:51
kUtils::kMemSet
kStatus kMemSet(void *dest, kByte fill, kSize size)
Sets a block of memory to the given byte value.