wahaha wrote:
"ottawajn дµÀ£º
"
Hi, There,
I want to declare a two-dimension array by
"float coeftemp1 [1024][512];" in Dev c++. It doesn't work.
But, if I change it to "float coeftemp1 [1024][500];".
It works. Could any one know the reason?
Thank you,
I think Brian is exactly right. Assume your float is 8 bytes and
1024x512x8 = 4k byte. This might be the maximum automatic space. Try to
use another method such as:
float **coeftemp1 ;
int i;
coeftemp1 = (float *)malloc(1024 * sizeof(int *));
for (i = 0; i < 1024; i++){
coeftemp1[i] = (float)malloc(512 * sizeof(float));
Please refrain from top-posting.
This being comp.lang.c++, the new operator is frequently more useful
than malloc(). Ignoring that, your usage of malloc() above is very
dangerously broken (and would probably fail to compile, anyway). The
types you're using to cast the result of malloc are completely wrong,
as is your sizeof(int *).
For this reason and several others, C++ users might prefer to do
something like:
float (*coeftemp1)[512] = new float[1024][512];
or, probably more commonly, with a change in how elements are accessed:
float *coeftempl = new float[1024 * 512];
(hopefully, substituting declared constants for the meaningless magic
numbers above).
Perhaps better, depending on the situation, would be to use a
std::vector<float>.
HTH,
Micah Cowan