johnsfine |
10-04-2012 07:29 PM |
Quote:
Originally Posted by errigour
(Post 4797613)
also that means I have to declare 1000 extra bytes just to have an array. seems kinda dumb.
|
You seem to be missing the point. Think about an array
char[3][3];
Code:
0 1 2
0 a b c
1 d e f
2 g h i
I showed indexes in blue and showed possible contents a .. i. There is no "extra". A 3x3 array has nine elements and you can use all nine. You can't use index 3, because the starting index is 0.
Quote:
Originally Posted by errigour
(Post 4797613)
also that means I have to declare 1000 extra bytes just to have an array. seems kinda dumb.
|
Or maybe you meant the multi-level allocation to allow the char** declaration to be correct. For a 500x1000 array, that multi-level allocation costs a lot more than 1000 extra bytes. Each allocation has overhead, plus the pointers are it least 4 bytes each.
If you worry about that overhead, use the alternate declaration that allows you to malloc a single chunk.
But at 500x1000, these details don't matter. That is 500KB of data plus about 6KB of overhead. That is one tenth of one percent of your total ram.
Quote:
Originally Posted by errigour
(Post 4797242)
char area_map[10000][10000];
|
But that is 100MB. That is a big enough fraction of your ram to take seriously, especially to ask why you want to have one version of that on the stack apparently just to copy it to another version allocated differently.
Quote:
Originally Posted by errigour
(Post 4797610)
what about my maximum ram I only have 512 when will my program cease?
|
Assuming you have a decent size hard drive, I suggest you allocate a few (2 or 3) GB of swap space, so that when your program uses too much memory it will just get very slow rather than crash. That should make such problems easier to diagnose, quantify and correct.
|