Thank you both.
I added alignment to 16 byte boundaries. But I must have overseen something.
A library I use can take a custom allocator function. If it gets one, it uses only these to allocate memory. if no custom one is passed, it uses this default:
Code:
static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
(void)ud;
(void)osize;
if (nsize == 0) {
free(ptr);
return NULL;
}
else
return realloc(ptr, nsize);
}
I've tried different implementations of a custom function with less and less features. None of that worked (the library functions crashed due to memory access error after a time).
Now I tried the very simplest version of a custom function I could come up with. It just allocs and returns the memory asked for. It doesn't care about freeing of memory, re-allocation, corruption checks, fragmentation or anything else.
Code:
void* LuaMemoryManager::alloc_impl_manual3( void* ptr, size_t osize, size_t nsize )
{
if (nsize)
{
std::vector<unsigned char>* mem = new std::vector<unsigned char>(nsize);
//yes, it will leak. don't care for now
return &(*mem)[0]; //returned memory position should be aligned by new
}
return NULL;
}
The problems/crashes remains.
I must do some fundamental error or understand some detail wrong. Any Ideas?