realbasic-plugins
[Top] [All Lists]

Re: How to dispose of memblock after REALPtrToMemoryBlock?

To: REALbasic Plugins <realbasic-plugins at lists dot realsoftware dot com>
Subject: Re: How to dispose of memblock after REALPtrToMemoryBlock?
From: Jonathan Johnson <jonj at realsoftware dot com>
Date: Mon, 13 Sep 2004 10:44:23 -0500
Delivered-to: realbasic-plugins at lists dot realsoftware dot com
References: <0A6B4F98C61DDB48B9DE3657B9BCD5A230A374 at ohexchciv2 dot civic1 dot ottawahospital dot on dot ca> <1A0F85BF-0527-11D9-815C-000A959DF1D2 at realsoftware dot com> <52E64216-0596-11D9-A634-000A95A69EA8 at ohri dot ca> <6C332A64-0598-11D9-B2B9-0003937BDA2C at realsoftware dot com> <78310828-0599-11D9-A634-000A95A69EA8 at ohri dot ca>

On Sep 13, 2004, at 10:27 AM, Peter K.Stys wrote:
...but how would I get the ptr to free it using free(REALMemoryBlockGetPtr(returnMemBlock)) if returnMemBlock has gone out of scope (and presumably is nil or garbage?)

You can store the pointer somewhere in your plugin.

I will be the only one ever calling these functions so is there a danger to free a pointer inside a memblock without RB's knowledge (making sure the block never gets accessed, and doing it right before it goes out of scope?)

Well, take this example:

void DoSomething()
{
        void *theData = GetTheDataSomehow();
        REALmemoryBlock mb = REALPtrToMemoryBlock( (Ptr)theData );

        CallMySpiffyFunctionThatNeedsAMemoryBlock( mb );

        // Now, we are done with the data
REALUnlockObject( mb ); // This is required because we are the ones who created the memoryblock,
                                                //  and now we want to destroy 
it
        free( theData ); // This is to free the actual memory
}

HTH,
Jon

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>