![]() |
|
#1
|
|||
|
|||
3D array dynamic memory allocationI am writing a code to read in a 3D gray scale image file into a program. I got a stack fault error when I originally wrote the code due to the size of the image file. I then tried to use malloc to allocate sufficient memory. The code compiles but I get several warnings telling me "differs in levels of indirection". I do not think I am doing this correctly. I have included the relevant parts of the code below. Any help would be appreciated.
CPP / C++ / C Code:
Thanks. Last edited by dsmith : 20-Feb-2004 at 08:47.
Reason: Added C syntax highlighting
|
|||
|
#2
|
||||
|
||||
|
Hello cj.
Wow! Three levels of indirection, my head hurts! First, this call is probably giving you problems. Image[i] should return a char **. Also, notice that you have an unsinged char as opposed to an unsigned char. CPP / C++ / C Code:
The whole thing should be more like: (assuming that your slices are first, followed by rows, followed by voxels CPP / C++ / C Code:
Once you get down to Image[i][j][k], what you are actually looking at is the charecter itself. It can be pretty confusing. What would really help I think to look at this is if you could also post your original code using the arrays if you have it. I am not quite sure what you are trying to "store" in this memory yet. Last edited by dsmith : 20-Feb-2004 at 09:40.
|
|
#3
|
|||
|
|||
additional codeHere is some additional code so that you can see what I am trying to do with the arrays. As far as what I am doing, I am writing a radiation transport code to calculate energy absorbtion using a CT image as a geometry. I am trying to read in bit wise a binary image file with different gray scale values (0 to 255). I am using the arrays so that each Image[i][j][k] is given a single value between 0 and 255. Then based upon the value I calculate position and distances between voxels along a path.
CPP / C++ / C Code:
These are examples of how I am using the data in the image array. Please let me know if more information is needed and I can attach the whole code. Thanks. Last edited by admin : 22-Apr-2007 at 10:50.
Reason: Add C syntax highlighting
|
|
#4
|
||||
|
||||
|
I am afraid I gave you some rather bad advice earlier
I avoid multiple indirection because it can be pretty complicated. To C it is just a big block of memory and then you have to take care of the divisions. There is an excellent post here with a very good explanation of two levels of indirection. Basically, instead of being able to access your data like CPP / C++ / C Code:
You would need to do something like: CPP / C++ / C Code:
Also, you would need to allocate all of this memory as the same chunk of memory (ie - it needs to be sequential) CPP / C++ / C Code:
which is exactly the same as using an array, except for the time that the memory is allocated. So after all this, you are probably back to the same problem. Your program either doesn't have access to this much contiguous memory or it can't reach it using standard memory allocation. How big does your memory need to be? What O/S and compiler are you using? I don't know that a dynamic memory allocation will help... |
Recent GIDBlog
Review: Gel laptop cooling pad by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| throwing an struct(with an array) through a function | knakworstje | C Programming Language | 5 | 15-Feb-2004 17:20 |
| c: array comparison | jack | C Programming Language | 7 | 26-Jan-2004 12:21 |
| Trying to create the game of life | warny_maelstrom | C Programming Language | 10 | 21-Jan-2004 22:14 |
| pointers and arrays | jack | C Programming Language | 4 | 15-Jan-2004 13:27 |
| Extra null element in an array | samtediou | MySQL / PHP Forum | 2 | 11-Dec-2003 12:52 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The