rtdb/kogmo_rtdb_rtmalloc.c
/*! \brief Allocate Memory for Object Data with Object Data Heap.
 * For internal use only.
 * returns Index-Pointer relative to Heap begin.
 */
\brief Allocate Memory for Object Data with Object Data Heap.
For internal use only.
returns Index-Pointer relative to Heap begin.
\ brief Allocate Memory for Object Data with Object Data Heap . For internal use only . returns Index - Pointer relative to Heap begin .
kogmo_rtdb_objsize_t
kogmo_rtdb_obj_mem_alloc (kogmo_rtdb_handle_t *db_h, kogmo_rtdb_objsize_t size )
{
  void *ptr = NULL;
  void *base = db_h->localdata_p -> heap;
  DBGL(DBGL_DB,"mem_alloc: heap pointers: base %p", 
       db_h->localdata_p -> heap);
  DBGL(DBGL_DB,"mem_alloc: %lli bytes (%lli used, %lli free)",
       (long long int) size,
       (long long int) db_h->localdata_p -> heap_used,
       (long long int) db_h->localdata_p -> heap_free);
  if ( size <= 0 ) return -1;
  kogmo_rtdb_heap_lock(db_h);
#if defined(RTMALLOC_tlsf)
  ptr = malloc_ex (size, base);
#elif defined(RTMALLOC_suba)
  ptr = suba_alloc(db_h->heapinfo, size, 0);
#else
  if ( size <= db_h->localdata_p -> heap_free )
    {
      ptr = base + db_h->localdata_p -> heap_used;
    }
#endif
  DBG("mem_malloc: at %p",ptr);
  if ( ptr == NULL )
    {
      kogmo_rtdb_heap_unlock(db_h);
      ERR("object mem_alloc failed for %i continuous bytes, %lli (discontinuous) bytes free", size,
          (long long int) db_h->localdata_p -> heap_free );
      return -1;
    }
  db_h->localdata_p -> heap_free -= size;
  db_h->localdata_p -> heap_used += size;
  kogmo_rtdb_heap_unlock(db_h);
  memset (ptr, 0, size);
  DBG("allocated mem cleared");
  return ptr-base;
}
kogmo_rtdb_objsize_t kogmo_rtdb_obj_mem_alloc ( kogmo_rtdb_handle_t * db_h , kogmo_rtdb_objsize_t size ) { void * ptr = NULL ; void * base = db_h -> localdata_p -> heap ; DBGL ( DBGL_DB , " " , db_h -> localdata_p -> heap ) ; DBGL ( DBGL_DB , " " , ( long long int ) size , ( long long int ) db_h -> localdata_p -> heap_used , ( long long int ) db_h -> localdata_p -> heap_free ) ; if ( size <= 0 ) return -1 ; kogmo_rtdb_heap_lock ( db_h ) ; #if defined ( RTMALLOC_tlsf ) ptr = malloc_ex ( size , base ) ; #elif defined ( RTMALLOC_suba ) ptr = suba_alloc ( db_h -> heapinfo , size , 0 ) ; #else if ( size <= db_h -> localdata_p -> heap_free ) { ptr = base + db_h -> localdata_p -> heap_used ; } #endif DBG ( " " , ptr ) ; if ( ptr == NULL ) { kogmo_rtdb_heap_unlock ( db_h ) ; ERR ( " " , size , ( long long int ) db_h -> localdata_p -> heap_free ) ; return -1 ; } db_h -> localdata_p -> heap_free -= size ; db_h -> localdata_p -> heap_used += size ; kogmo_rtdb_heap_unlock ( db_h ) ; memset ( ptr , 0 , size ) ; DBG ( " " ) ; return ptr - base ; }
\brief Allocate Memory for Object Data with Object Data Heap.
\ brief Allocate Memory for Object Data with Object Data Heap .
// speedup: round size to page_size (achieved with tlsf parameters) /* dont zero*/