Re: Really stupid c question
Re: Really stupid c question
- Subject: Re: Really stupid c question
- From: Nat! <email@hidden>
- Date: Fri, 12 Apr 2002 00:44:32 +0200
Am Donnerstag den, 11. April 2002, um 11:59, schrieb Brian Williams:
Hi everyone,
I have a stupid c question about Cocoa. Coming from the land of
Java I am not
really used to dealing with memory and such. I am trying to make a
BOOL array
to have a one bit rep of the screen for a screen saver. (it's only
for objects
to reference not for drawing) When I try to make a BOOL array
like this ->
BOOL test[786432] /*1024 *768 ==786432*/ it crashes. I am guessing
that I am
going out of the local memory space? or something like that.
Any help is greatly appreciated
Thanks
That's because you allocated the array on the stack. I am unaware
about the size restrictions on the stack, but apparently 786432
bytes is a trifle too much.
You could allocate it statically like this:
static BOOL test[786432];
The difference is that the array will not go away after your
methods invocation and the contents will remain and reappear in the
next method call. This static array will never go away during the
lifetime of your screensaver. An alternative may be malloc() [sorta
like new BOOL[ 786432], but you need to call free() on the memory
some time too]
Cheers
Nat!
P.S. A good C book will not be a senseless waste of your money :)
Harbison, Steele "C A Reference Manual" - is the best. It's not a
primer in programming though.
------------------------------------------------------
Some people drink deep from the fountains of life, and
some just gargle. -- DLR
_______________________________________________
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.