}
chain->len = size;
- chain->pos = chain->begin;
+ chain->pos = align_ptr (chain->begin, MEM_ALIGNMENT);
chain->next = NULL;
STAT_LOCK ();
mem_pool_stat->chunks_allocated++;
#endif
chain->len = size;
chain->pos = chain->begin;
+ chain->pos = align_ptr (chain->begin, MEM_ALIGNMENT);
chain->lock = NULL;
chain->next = NULL;
STAT_LOCK ();
STAT_UNLOCK ();
return new->begin;
}
- tmp = cur->pos;
- cur->pos += size;
+ tmp = align_ptr (cur->pos, MEM_ALIGNMENT);
+ cur->pos = tmp + size;
STAT_LOCK ();
mem_pool_stat->bytes_allocated += size;
STAT_UNLOCK ();
STAT_UNLOCK ();
return new->begin;
}
- tmp = cur->pos;
- cur->pos += size;
+ tmp = align_ptr (cur->pos, MEM_ALIGNMENT);
+ cur->pos = tmp + size;
STAT_LOCK ();
mem_pool_stat->bytes_allocated += size;
STAT_UNLOCK ();
struct f_str_s;
+#define MEM_ALIGNMENT sizeof(unsigned long) /* platform word */
+#define align_ptr(p, a) \
+ (guint8 *) (((uintptr_t) (p) + ((uintptr_t) a - 1)) & ~((uintptr_t) a - 1))
+
/**
* Destructor type definition
*/
* Macro that return free space in pool page
* @param x pool page struct
*/
-#define memory_pool_free(x) ((x)->len - ((x)->pos - (x)->begin))
+#define memory_pool_free(x) ((x)->len - (align_ptr((x)->pos, MEM_ALIGNMENT) - (x)->begin))
#endif