• Advertisement
Sign in to follow this  

GetMem and FreeMem

This topic is 4368 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

how to register these 2 methods to AngelScript since it is returning a pointer to a long ? //--------------------------------------------------------- long* CObjectScript::GetMemory(long sizeBytes) { unsigned char *buffer; getmem (&buffer, sizeBytes); return ((long*)buffer); } //--------------------------------------------------------- void CObjectScript::FreeMemory(long* buffer) { free (buffer); }

Share this post


Link to post
Share on other sites
Advertisement
I suggest that you register a new data type to hold pointers like this.


// Register the object type
engine->RegisterObjectType("ptr", sizeof(void*), asOBJ_PRIMITIVE);

// Now register the GetMem and FreeMem to handle that type
engine->RegisterGlobalFunction("ptr GetMem(uint)", asFUNCTION(GetMem), asCALL_CDECL);
engine->RegisterGlobalFunction("void FreeMem(ptr)", asFUNCTION(FreeMem), asCALL_CDECL);


Regards,
Andreas

Share this post


Link to post
Share on other sites

so now i just do this in the script:


ptr Test = GetMem(1000);

FreeMem(Test);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement