Re: How to Management Bytes?
Re: How to Management Bytes?
- Subject: Re: How to Management Bytes?
- From: Fritz Anderson <email@hidden>
- Date: Sun, 19 Jun 2011 10:40:52 -0500
On 19 Jun 2011, at 10:28 AM, Bing Li wrote:
> I got another problem in the following method. A byte array is used to save
> data transmitted from a remote node and the size is different for each
> message. I think I need to release the byte array after it is used. However,
> the system got crashed if the line, free(receivedBytes), was added. So I
> made a copy for the receivedMessage. But it still crashed.
free() is for memory allocated in the heap by the malloc() family of functions. It is an error to apply it to memory on the stack, as in the case of your receivedBytes. That memory will be returned to the system when receivedBytes goes out of scope. It will be illegal to use that array after that.
This is an extremely elementary fact of the C programming language. If you don't know it, you can't program in C. I believe you have already been advised to stop whatever you are doing, and read an introductory-level book on C. Do that. If you don't, you will be wasting your time, and ours.
— F
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden