1 //----------------------------------------------------------------------
2 // This software is part of the OpenBeOS distribution and is covered
3 // by the OpenBeOS license.
5 // Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net
6 //---------------------------------------------------------------------
8 #ifndef _UDF_MEMORY_CHUNK_H
9 #define _UDF_MEMORY_CHUNK_H
13 #include <util/kernel_cpp.h>
15 /*! Simple class to encapsulate the boring details of allocating
16 and deallocating a chunk of memory.
18 The main use for this class is cleanly and simply allocating
19 arbitrary chunks of data on the stack.
23 MemoryChunk(uint32 blockSize
)
25 , fData(malloc(blockSize
))
30 MemoryChunk(uint32 blockSize
, void *blockData
)
43 uint32
Size() { return fSize
; }
44 void* Data() { return fData
; }
45 status_t
InitCheck() { return Data() ? B_OK
: B_NO_MEMORY
; }
49 MemoryChunk(const MemoryChunk
&);
50 MemoryChunk
& operator=(const MemoryChunk
&);
57 template <uint32 size
>
58 class StaticMemoryChunk
{
60 uint32
Size() { return size
; }
61 void* Data() { return reinterpret_cast<void*>(fData
); }
62 status_t
InitCheck() { return B_OK
; }
68 #endif // _UDF_MEMORY_CHUNK_H