Re: Can't get custom allocation function to work
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Can't get custom allocation function to work
 
- From: Ralph Hempel <rhempel@...>
 
- Date: 2009年3月24日 10:34:03 -0400
 
kathrin_69@gmx.de wrote:
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.
<snip>
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;
}
Ummm, besides the leak, should you not be returning:
 return( mem )
since mem is already a pointer to the memory you allocated?
And this expression &(*mem)[0] is very strange. I parse that as:
(the adress of ( (the contents of mem) ???? )
my compiler warns that the subscripted value is neither an array nor a
pointer...
Ralph