Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating a Handle from an existing memory




On Jun 11, 2007, at 1:03 PM, Yaron Tadmor wrote:

Hi,

Is there a way to create a handle from an already existing memory area? For example, can I do something like this:

Char *myP = new char[100];

Handle myH = MemoryToHandle (myP, 100);
No. There never has been. If there were, it would be in MacMemory.h. If you anticipate needing the functionality of a Handle you should allocate the memory that way initially.

Besides, if you did something like the above it wouldn't work anyway. The memory in your example was allocated with a C++ new allocation. You then pass it off to a Memory Manager data type, which would ultimately release it with free instead of your C++ delete. It needs to be released with:

delete [] myP;

and that's not going to happen inside DisposeHandle.

You've been programming for a long time. Why are you asking such questions?

Larry


I saw there is a PtrToHand and PtrToXHand, but they use copying.

Thanx

Yaron Tadmor
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden
References: 
 >Creating a Handle from an existing memory (From: "Yaron Tadmor" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.