lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


"kathrin_69@gmx.de" <kathrin_69@gmx.de> writes:

> Hi,
>
> I'm trying to replace the Lua default l_alloc function with my own
> one. My aim is to have all memory Lua allocates inside a single array
> of pre-allocated memory.
>
> 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.
>
>
> void* alloc_impl_manual( 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?

You ignore osize.

-- 
David Kastrup