GCC actually allows some dynamic allocation of built-in arrays, which is, of course, non-standard behavior and something you should _never_ rely upon. BCC, on the other hand, doesn't allow this (in conformance with the standard).
If you're looking for a good, portable implementation of multi-dimensional arrays, try the MultiArray library from www.boost.org. This will provide a good interface for multi-dimensional arrays and will allow you to hide the memory management.
Matt
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Some of the functionality he is looking for can be obtained from the <valarray> header. Look at the link below for a reference. However, that's the best the Standard Library gets.
Some of the functionality he is looking for can be obtained from the <valarray> header. Look at the link below for a reference. However, that's the best the Standard Library gets.
Thanks!
I'll give Curtis' code a try. I have no idea what is written there (damn pointers), but if it works I won't complain.
I will check out Boost as well. I'm rather new to c++ and exected it to be a lot like Java... Not always, apparently.
Johan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you need help with my code, you could upload it to my ftp at ftp://curtis.servebeer.com/ in the uploads dir. I can fix it there, then you can get it back.
Curtis
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There's no one home in the users forum, so I'll give it a try here:
Suppose I want to put a bitmap in a 2D array in memory. I determine the values for width and height in runtime (int w, h; ) and create the array..
int (*bitmap)[h];
bitmap= new int[w][h];
then I can, for instance, get R, G or B values and put them in the array.
This works fine With GCC, but Borland 5.5 gives an error: it refuses the h. If I put a number there, like
int (*bitmap)[123];
bitmap= new int[w][123];
BCC compiles without objections. But since the dimensions of the bitmap are determined in runtime that is not an option.
What's going on here? Is my code ok or isn't it?
Johan
GCC actually allows some dynamic allocation of built-in arrays, which is, of course, non-standard behavior and something you should _never_ rely upon. BCC, on the other hand, doesn't allow this (in conformance with the standard).
If you're looking for a good, portable implementation of multi-dimensional arrays, try the MultiArray library from www.boost.org. This will provide a good interface for multi-dimensional arrays and will allow you to hide the memory management.
Matt
Isn't there, he asked in total ignorance, some useful stuff in this area in the STL?
Wayne (the dumb)
how about this?
// My code
int **bitmap = new int* [w];
for(int count = 0; count < h; count++)
bitmap[count] = new int[h];
//End of my code
Curtis
That is the notation, the ** notation that I have seen more often. See it seldom enough to have it freakin' confuse me every time.
In my work, most of the time its faster to work with 1D arrays, even with the overhead of the calculations like:
index = column + (row - 1) * number_columns;
Can't always do that though.
;-)
Wayne
Some of the functionality he is looking for can be obtained from the <valarray> header. Look at the link below for a reference. However, that's the best the Standard Library gets.
http://www-h.eng.cam.ac.uk/help/tpl/languages/C++/doc/node44.html
The multidimensional array class is probably easier to use and provides semantics closer to what he's trying to do.
Some of the functionality he is looking for can be obtained from the <valarray> header. Look at the link below for a reference. However, that's the best the Standard Library gets.
http://www-h.eng.cam.ac.uk/help/tpl/languages/C++/doc/node44.html
The multidimensional array class is probably easier to use and provides semantics closer to what he's trying to do.
Cool, thanks for helping my pathetic memory.
Wayne
Thanks!
I'll give Curtis' code a try. I have no idea what is written there (damn pointers), but if it works I won't complain.
I will check out Boost as well. I'm rather new to c++ and exected it to be a lot like Java... Not always, apparently.
Johan
Just for sick grins, I will point out that C# may seem more like Java than C++.
:-)
Wayne
If you need help with my code, you could upload it to my ftp at ftp://curtis.servebeer.com/ in the uploads dir. I can fix it there, then you can get it back.
Curtis