Menu

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

AllocInfoget_ai (SizeT offset)
 Return AllocInfo pointer from offset in data member.
SizeTfind_first_fit (SizeT bytes, SizeT &to_allocate)
 Find free memory for allocation via first fit algorithm.
SizeTfind_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:
Author:
Philipp Werner

Member Typedef Documentation

template<uint64_t size>
typedef SmallestUnsignedTypeSelector<size>::type object::RawStorage< size >::SizeT

Type used for addressing inside storage (smallest for given size).


Constructor & Destructor Documentation

template<uint64_t size>
object::RawStorage< size >::RawStorage (  )  [inline]

Constructor.


Member Function Documentation

template<uint64_t size>
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().

template<uint64_t size>
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().

template<uint64_t size>
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().

template<uint64_t size>
void object::RawStorage< size >::free ( uint8_t *  p  )  [inline]
template<uint64_t size>
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

template<uint64_t size>
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().

template<uint64_t size>
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: