Re: general questions (another noob)
Re: general questions (another noob)
- Subject: Re: general questions (another noob)
- From: Jens Bauer <email@hidden>
- Date: Sun, 7 Sep 2003 22:35:32 +0200
Hi Oscar and Aubrey,
On Saturday, Sep 6, 2003, at 19:55 Europe/Copenhagen, Sscar Morales
Vivs wrote:
I never made any tests on this, however, if looking at the sizes..
int 4 bytes
float 4 or 8 bytes (usually 8!)
object 4 bytes (pointer, however, further comparison would be needed
if the pointer isn't the same)
I would have thought that float is 4 bytes, and you need to use double
for 8 byte floating point stuff. That's stadarized IEEE stuff (AFAIK).
You can easily find out whether your compiler compiles it as a 4 byte
float (single precision) or an 8 byte float (double precision), by
using the following code:
- (void)awakeFromNib
{
int i;
float f;
NSObject *o;
i = 10;
f = 10;
o = NULL;
fprintf(stderr, "int-size :%d\n", sizeof(i));
fprintf(stderr, "float-size :%d\n", sizeof(f));
fprintf(stderr, "object-size:%d\n", sizeof(o));
}
Now, a bunch of people would argue that the size of the object isn't
correct, so I'd like to ask... What is the size of an object? -The
pointer or the object itself?
-When comparing the pointers, it's just 4 bytes in the best case, but
if you need to compare the entire object, you'd have to ask a method in
the object to compare itself to another object, so you would have *no*
idea on how much data is actually compared. It could be thousands of
strings, if you're unlucky.
The size of an NSObject is 4 bytes (for the isa, which is a pointer to
its class).
You could change the sizeof(i) to sizeof(int) if you want
Also int size isn't fixed in the standard, although it's almost always
4 bytes in modern machines. Used to be less.
Yep, it used to be 2 bytes... If you want to be sure, you can...
short int i;
long int l;
However, you'd probably prefer using...
short i;
long l;
:)
Hope that helps.
Heh, I'm only answering a question that Aubrey asked, and didn't really
want to go this deep into it. ;)
In fact, the best way to find out about the speed, would be to make a
small test application that does a 100000 compares, then measure how
long each comparison takes.
Ofcourse, you'd only need this, in case you are working with much data.
If you do 1000 compares or less, you wouldn't notice any difference.
Love,
Jens
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.