Re: The cost of using objects rather than plain C variables

2013-07-12 Thread Jean-Daniel Dupas
Le 12 juil. 2013 à 08:41, Vincent Habchi 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 m

Re: The cost of using objects rather than plain C variables

2013-07-11 Thread Vincent Habchi
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

Re: The cost of using objects rather than plain C variables

2013-07-09 Thread Marcel Weiher
On Jul 8, 2013, at 18:04 , Jens Alfke wrote: > > On Jul 7, 2013, at 1:37 PM, Frederick Bartram wrote: > >> Have you tried using NSData to store C-arrays? > > Or alternatively use NSPointerValue to wrap a pointer to a malloc’ed C array > as an object. It seems to me that an array of float

Re: The cost of using objects rather than plain C variables

2013-07-08 Thread Mike Abdullah
On 8 Jul 2013, at 18:14, Andy Lee wrote: > On Jul 8, 2013, at 1:08 PM, Boyd Collier wrote: >> Your suggestion sounded worth learning about, but it appears that there's no >> such creature as NSPointerValue. > > I'm guessing Jens meant +[NSValue valueWithPointer:]. > >> Did you perhaps mea

Re: The cost of using objects rather than plain C variables

2013-07-08 Thread Scott Ribe
On Jul 8, 2013, at 11:08 AM, Boyd Collier wrote: > Your suggestion sounded worth learning about, but it appears that there's no > such creature as NSPointerValue. Did you perhaps mean NSPointerArray? I suspect it was instead NSValue and pointerValue/setPointerValue to which he was referring.

Re: The cost of using objects rather than plain C variables

2013-07-08 Thread Andy Lee
On Jul 8, 2013, at 12:30 PM, Vincent Habchi wrote: > On 8 juil. 2013, at 18:04, Jens Alfke wrote: >> On Jul 7, 2013, at 1:37 PM, Frederick Bartram wrote: >> >>> Have you tried using NSData to store C-arrays? > > No, since my initial problem was to be able to extend the buffer as the > number

Re: The cost of using objects rather than plain C variables

2013-07-08 Thread Andy Lee
On Jul 8, 2013, at 1:08 PM, Boyd Collier wrote: > Your suggestion sounded worth learning about, but it appears that there's no > such creature as NSPointerValue. I'm guessing Jens meant +[NSValue valueWithPointer:]. > Did you perhaps mean NSPointerArray? I'm guessing not, since NSPointerArr

Re: The cost of using objects rather than plain C variables

2013-07-08 Thread Boyd Collier
Your suggestion sounded worth learning about, but it appears that there's no such creature as NSPointerValue. Did you perhaps mean NSPointerArray? On Jul 8, 2013, at 9:04 AM, Jens Alfke wrote: > > On Jul 7, 2013, at 1:37 PM, Frederick Bartram wrote: > >> Have you tried using NSData to s

Re: The cost of using objects rather than plain C variables

2013-07-08 Thread Vincent Habchi
On 8 juil. 2013, at 18:04, Jens Alfke wrote: > On Jul 7, 2013, at 1:37 PM, Frederick Bartram wrote: > >> Have you tried using NSData to store C-arrays? No, since my initial problem was to be able to extend the buffer as the number of primitive read grew. NSData would not do that. Alternatively

Re: The cost of using objects rather than plain C variables

2013-07-08 Thread Jens Alfke
On Jul 7, 2013, at 1:37 PM, Frederick Bartram wrote: > Have you tried using NSData to store C-arrays? Or alternatively use NSPointerValue to wrap a pointer to a malloc’ed C array as an object. —Jens ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple

Re: The cost of using objects rather than plain C variables

2013-07-07 Thread Frederick Bartram
> Is there any hope in the future to be able to store simple types like int or > floats in NSArrays? Have you tried using NSData to store C-arrays? *- * Frederick Bartram * PGP key id: 0x63fa758 keyserver: http://keyserver.pgp.com */ smime.p7s De

Re: The cost of using objects rather than plain C variables

2013-07-07 Thread Jens Alfke
On Jul 7, 2013, at 1:08 AM, Vincent Habchi wrote: > My initial reasoning was very (too) simple: I have a 20 MB file made up of > strings, if I store those strings in objects, even with a small overhead, it > should not top 30 or 40 MB. It turned out I was plainly wrong, at least the > way I i

Re: The cost of using objects rather than plain C variables

2013-07-07 Thread Scott Ribe
And while we're on the subject of speed, you're already dealing with threads, you're already prefixing the values with a count, if you get to a format where values in the input file are fixed-length, then you can find sections 2 & 3 without reading 1 & 2, so you could load the sections in parall

Re: The cost of using objects rather than plain C variables

2013-07-07 Thread Scott Ribe
On Jul 7, 2013, at 10:38 AM, Vincent Habchi wrote: > Oh, just that since I moved from plain BSD/Qt3 to MacOS/Cocoa, I swore not to > write any line of C++ ever again. But that’s just a personal commitment ;) If Qt is the majority of your experience with C++, then I understand wanting to avoid i

Re: The cost of using objects rather than plain C variables

2013-07-07 Thread Vincent Habchi
Hi! You’re right to point that CFtypes exist: I often overlook these and that’s stupid of me. > Why? What's wrong with a simple array? Nothing. Well, at first, I was looking for a self expanding array, given that I didn’t know the size beforehand. > (Or, I would argue, though it's not a popul

Re: The cost of using objects rather than plain C variables

2013-07-07 Thread Scott Ribe
On Jul 7, 2013, at 1:33 AM, Vincent Habchi wrote: > Is there any hope in the future to be able to store simple types like int or > floats in NSArrays? Why? What's wrong with a simple array? (Or, I would argue, though it's not a popular strategy, what's wrong with std::vector?) Now if you real

Re: The cost of using objects rather than plain C variables

2013-07-07 Thread dangerwillrobinsondanger
Sent from my iPhone On 2013/07/07, at 16:33, Vincent Habchi wrote: > Hi! > Thanks to all for your quick and kind answers. > >> You're comparing apples to oranges. > > That’s a nice way of putting it! > >> You were storing strings for each numeric value, now you're storing doubles. > > Ac

Re: The cost of using objects rather than plain C variables

2013-07-07 Thread Vincent Habchi
Quincey, > Each NSString has at least 4 bytes of overhead (the 'isa' pointer); each > character is UTF-16; each object is a multiple of 16 bytes. Your values may > not fit in the remaining 12 bytes of the smallest object (an input format > something like '0.xe-nn', which isn't an unlikely forma

Re: The cost of using objects rather than plain C variables

2013-07-07 Thread Vincent Habchi
Hi! Thanks to all for your quick and kind answers. > You're comparing apples to oranges. That’s a nice way of putting it! > You were storing strings for each numeric value, now you're storing doubles. Actually just floats, in order to save space. > You could have tried NSNumber objects inste

Re: The cost of using objects rather than plain C variables

2013-07-06 Thread Quincey Morris
On Jul 6, 2013, at 23:06 , Vincent Habchi wrote: > instead of [myMutableArray add:[[NSString stringFromCString:… encoding:…] > componentsSeparatedBy:@", "]], I just wrote: sscanf (myLine, "%f, %f, %f", &t > [0], &t [1], &t [2]) > How come I get such a large discrepancy in memory usage between

Re: The cost of using objects rather than plain C variables

2013-07-06 Thread Ken Thomases
On Jul 7, 2013, at 1:06 AM, Vincent Habchi wrote: > At first, the TIN file didn’t include the exact number of > vertices/normals/triangles, so I had to decode the whole file in order to > know how large a buffer I should allocate to store each of the three data > types. Meanwhile I did record t

Re: The cost of using objects rather than plain C variables

2013-07-06 Thread T.J. Usiyan
The short answer is yes the overhead of an object versus a primitive value is huge. The longer answer is that however tiny you think the difference might be, you need to multiply it by somewhere between 200,000 and 600,000 to really get a sense for the difference in context. For the same reasons t

The cost of using objects rather than plain C variables

2013-07-06 Thread Vincent Habchi
Hi everybody, the tiny iOS app I work on currently begins by decoding 3D data in the form of a TIN: vertices, normals then triangles. There are about 200 000 of the two formers, and 400 000 of the latters (needless to say, at a later stage, I am going to improve speed by using some kind of tili