• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Static data?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Static data?


  • Subject: Re: Static data?
  • From: Markian Hlynka <email@hidden>
  • Date: Tue, 6 Jul 2004 16:26:35 -0600
  • Illegal-object: Syntax error in Cc: address found on sunkay.cs.ualberta.ca: Cc: <email@hidden><email@hidden> ^-missing end of address

The advantage of static or automatic storage (as opposed to heap allocated storage) is that you do *not* need to handle errors, cause there will be none, ...
The errors appear at app launch time. Even more likely as malloc(), as there are tighter limitations.

I do not know what you mean with "even more likely" -- but for the coder it's certainly better just to have the OS refuse to load the program if it makes memory requirements which it cannot fulfill, rather than the need to check every single trivial allocation (for which there would perhaps anyway be no graceful way to handle an allocation fault).



remember, allocation on the stack happens when a function is called too. in this case for sure, and _probably when an app launches,


int foo[1024][1024][1024];

should be faster than using malloc or new. malloc/new need to look for memory in the heap and return it. Allocating on the stack is just a matter of incrementing the stack pointer.


So, now, the previous post confused me. What is the _correct way of doing this:


int foo[1024][1024][1024];

dynamically?

in C++ I'd do

int*** foo;
foo = new foo**[1024]
//now do a for loop and allocate foo[i]= new foo*[1024]
//and then another for loop for foo[i][j] = new foo[1024]

is there a better/more proper way to do this in C++?

What about in C? obviously I could just do
int* foo = malloc(3*1024*sizeof(int))
and then do the indices manually.

is there a better/proper way to do any/either of these?

Markian
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Static data?
      • From: Markus Hitter <email@hidden>
    • Re: Static data?
      • From: Creed Erickson <email@hidden>
References: 
 >Static data? (From: "Christopher Beck" <email@hidden>)
 >Re: Static data? (From: Pavol Markovic <email@hidden>)
 >Re: Static data? (From: Markus Hitter <email@hidden>)
 >Re: Static data? (From: Markus Hitter <email@hidden>)
 >Re: Static data? (From: Allan Odgaard <email@hidden>)

  • Prev by Date: shell script to selectively copy files?
  • Next by Date: Disabling a Processor
  • Previous by thread: Re: Static data?
  • Next by thread: Re: Static data?
  • Index(es):
    • Date
    • Thread