object::RawStorage< size > Class Template Reference
Storage for raw data blocks. More...
#include <RawStorage.h>
Data Structures | |
struct | AllocInfo |
Memory management information. In front of each allocated block. More... | |
Public Types | |
typedef SmallestUnsignedTypeSelector < size >::type | SizeT |
Type used for addressing inside storage (smallest for given size). | |
Public Member Functions | |
RawStorage () | |
Constructor. | |
uint8_t * | alloc (SizeT bytes) |
Allocate memory. | |
void | free (uint8_t *p) |
Free memory. | |
SizeT | get_length (uint8_t *p) |
Return length of allocated memory block. | |
Protected Member Functions | |
AllocInfo * | get_ai (SizeT offset) |
Return AllocInfo pointer from offset in data member. | |
SizeT * | find_first_fit (SizeT bytes, SizeT &to_allocate) |
Find free memory for allocation via first fit algorithm. | |
SizeT * | find_allocated_block (uint8_t *p) |
Find allocated memory for freeing. | |
Protected Attributes | |
uint8_t | data [size] |
Buffer for memory to allocate and memory management information (AllocInfo structs). | |
SizeT | first_allocated |
Offset in data where we find first AllocInfo instance (if alloc_count != size). |
Detailed Description
template<uint64_t size>
class object::RawStorage< size >
Storage for raw data blocks.
Uses in place linked list for allocated/free blocks management. That's why it's not possible to allocate size
Bytes. But management information is kept as small as possible by using the smallest possible integer type for internal addressing.
Over time the storage may suffer from memory fragmentation.
- Template Parameters:
-
size Number of bytes to use for storage.
- Logging:
- Define RAWSTORAGE_LOG_USAGE before including RawStorage.h for logging alloc() and free() calls on RawStorage objects.
- Define RAWSTORAGE_FULL_MEM_INFO to log complete RawStorage status on alloc() and free() calls.
Member Typedef Documentation
typedef SmallestUnsignedTypeSelector<size>::type object::RawStorage< size >::SizeT |
Type used for addressing inside storage (smallest for given size).
Constructor & Destructor Documentation
object::RawStorage< size >::RawStorage | ( | ) | [inline] |
Constructor.
Member Function Documentation
uint8_t* object::RawStorage< size >::alloc | ( | SizeT | bytes | ) | [inline] |
Allocate memory.
- Parameters:
-
bytes Number of bytes to allocate
- Returns:
- Pointer to allocated memory on success, NULL otherwise.
References object::RawStorage< size >::AllocInfo::block_length, object::RawStorage< size >::find_first_fit(), object::RawStorage< size >::get_ai(), and object::RawStorage< size >::AllocInfo::next_allocated.
Referenced by object::RawStorageAllocator< tag, mem_size >::alloc().
SizeT* object::RawStorage< size >::find_allocated_block | ( | uint8_t * | p | ) | [inline, protected] |
Find allocated memory for freeing.
- Parameters:
-
p [in] Pointer to allocated block
- Returns:
- Pointer to next_allocated offset of previous allocated block or NULL if there is no allocated block that fits the requirements.
References FAMOUSO_ASSERT, object::RawStorage< size >::first_allocated, object::RawStorage< size >::get_ai(), and object::RawStorage< size >::AllocInfo::next_allocated.
Referenced by object::RawStorage< size >::free().
SizeT* object::RawStorage< size >::find_first_fit | ( | SizeT | bytes, | |
SizeT & | to_allocate | |||
) | [inline, protected] |
Find free memory for allocation via first fit algorithm.
- Parameters:
-
bytes [in] Number of bytes to allocate to_allocate [out] Offset in data to allocate (AllocInfo)
- Returns:
- Pointer to next_allocated offset of previous allocated block or NULL if there is no empty block that fits the requirements.
References object::RawStorage< size >::AllocInfo::block_length, FAMOUSO_ASSERT, object::RawStorage< size >::first_allocated, object::RawStorage< size >::get_ai(), and object::RawStorage< size >::AllocInfo::next_allocated.
Referenced by object::RawStorage< size >::alloc().
void object::RawStorage< size >::free | ( | uint8_t * | p | ) | [inline] |
Free memory.
- Parameters:
-
p Pointer to memory returned by previous call to alloc()
Invalid p catched by assert.
References object::RawStorage< size >::AllocInfo::block_length, object::RawStorage< size >::data, FAMOUSO_ASSERT, object::RawStorage< size >::find_allocated_block(), FOR_FAMOUSO_ASSERT_ONLY, object::RawStorage< size >::get_ai(), and object::RawStorage< size >::AllocInfo::next_allocated.
Referenced by object::RawStorageAllocator< tag, mem_size >::free().
AllocInfo* object::RawStorage< size >::get_ai | ( | SizeT | offset | ) | [inline, protected] |
Return AllocInfo pointer from offset in data member.
References object::RawStorage< size >::data.
Referenced by object::RawStorage< size >::alloc(), object::RawStorage< size >::find_allocated_block(), object::RawStorage< size >::find_first_fit(), object::RawStorage< size >::free(), and object::RawStorage< size >::get_length().
SizeT object::RawStorage< size >::get_length | ( | uint8_t * | p | ) | [inline] |
Return length of allocated memory block.
- Parameters:
-
p Pointer to memory returned by previous call to alloc()
Does not check if pointer p is valid!
References object::RawStorage< size >::AllocInfo::block_length, object::RawStorage< size >::data, and object::RawStorage< size >::get_ai().
Field Documentation
uint8_t object::RawStorage< size >::data[size] [protected] |
Buffer for memory to allocate and memory management information (AllocInfo structs).
Referenced by object::RawStorage< size >::free(), object::RawStorage< size >::get_ai(), and object::RawStorage< size >::get_length().
SizeT object::RawStorage< size >::first_allocated [protected] |
Offset in data where we find first AllocInfo instance (if alloc_count != size).
Referenced by object::RawStorage< size >::find_allocated_block(), and object::RawStorage< size >::find_first_fit().
The documentation for this class was generated from the following file:
- include/object/RawStorage.h