Re: The cost of using objects rather than plain C variables
Re: The cost of using objects rather than plain C variables
- Subject: Re: The cost of using objects rather than plain C variables
- From: Jean-Daniel Dupas <email@hidden>
- Date: Fri, 12 Jul 2013 08:59:48 +0200
Le 12 juil. 2013 à 08:41, Vincent Habchi <email@hidden> a écrit :
> Hi!
>
> Sorry for this late answer, I was a bit swamped lately.
>
>> NSData wouldn't let you, but NSMutableData would, with methods like appendBytes:length:, appendData:, increaseLengthBy:, etc. The underlying buffer might have to move around if it cannot be extended in place, just as it would if you use C realloc() calls.
>
> In fact, I overlooked that completely. I just fear building a buffer from zero to something like 400,000 * 3 * 4 bytes = just under 5 MiB would imply too many moves as you mention.
If you know how large your data will be and want to avoid the realloc cost, you can just create your mutable data using -initWithCapacity: .
And even if the size end up to be larger than your initial capacity, the mutable data will do the right thing and increase the capacity.
> Now, I am anyway moving towards a binary file that would be fed directly into the buffer rather than needing decoding, and partitioning it into several chunks in order to optimize the number of triangles displayed. I think I’ll use NSData to store these chunks.
>
> Thanks to all for the precious help!
> Vincent
>
-- Jean-Daniel
_______________________________________________
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