util-memory: Expose aligned_offset to code

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2018-01-19 20:45:15 +01:00
parent 67099c2b23
commit adafbf40ca
2 changed files with 5 additions and 6 deletions

View file

@ -20,10 +20,6 @@
#include "util-memory.h" #include "util-memory.h"
#include <cstdlib> #include <cstdlib>
inline size_t aligned_offset(size_t align, size_t size) {
return ((size / align) + 1) * align;
}
void* util::malloc_aligned(size_t align, size_t size) { void* util::malloc_aligned(size_t align, size_t size) {
// Ensure that we have space for the pointer and the data. // Ensure that we have space for the pointer and the data.
size_t asize = aligned_offset(align, size + sizeof(void*)); size_t asize = aligned_offset(align, size + sizeof(void*));

View file

@ -22,6 +22,9 @@
#include <malloc.h> #include <malloc.h>
namespace util { namespace util {
inline size_t aligned_offset(size_t align, size_t pos) {
return ((pos / align) + 1) * align;
}
void* malloc_aligned(size_t align, size_t size); void* malloc_aligned(size_t align, size_t size);
void free_aligned(void* mem); void free_aligned(void* mem);
@ -55,11 +58,11 @@ namespace util {
} }
inline pointer allocate(size_type n) { inline pointer allocate(size_type n) {
return (pointer)_aligned_malloc(n*sizeof(value_type), N); return (pointer)malloc_aligned(n*sizeof(value_type), N);
} }
inline void deallocate(pointer p, size_type) { inline void deallocate(pointer p, size_type) {
_aligned_free(p); free_aligned(p);
} }
inline void construct(pointer p, const value_type & wert) { inline void construct(pointer p, const value_type & wert) {