Re: Is this a memory problem?



Jean-David Beyer wrote:
Bryan Heit wrote:

Patrick wrote:

"syang8" <syang8@xxxxxxxxx> wrote in message
news:1152036094.699638.87890@xxxxxxxxxxxxxxxxxxxxxxxxxxxx



I use Kdevelop to build some scientific simulation on Linux. If I set
the size of an array N = 8000, the program works fine. However, if I
set the array N some number greater than 10000 (actually, what I need
is 80000), the program has segmentation error. The intersting thing
is that the positions reporting segmentation error are different if
I set N to be different values.

What problem is this usually?


It's a problem with the faulty program code, always. Debug your
application
carefully step-by-step to discover the cause.



My guess is the problem is in the way you are accessing the array. I've
made the same mistake myself on more then one occasion.

I think that you're using a too small an integer for storing array
locations. For example, a 16-bit pointer can only describe ~65,500
unique array positions. So for an array with more then ~65,500 elements
you'll need a larger (i.e. 24-bit or 32-bit) pointer to access the
array. This would explain why your code works fine with smaller arrays
but fails with larger ones.

Bryan


Well, sort of. I believe all pointers these days, on 32-bit machines, are 32
bits.

It depends on the programming language. I don't know Kdevelop, but some programming languages allow you to pick the size of integer you use to reference the pointer. This was common in older languages, although I think that you can still do this in C/C++. I don't think that java and newer languages allow you to do this.

Bryan
.



Relevant Pages

  • Re: char **argv & char *argv[]
    ... "pointer to pointer to char". ... >> pointer)) pointing to the first element of an array. ... so we have to start adding more context. ... type "pointer to char", rather than "array MISSING_SIZE of char". ...
    (comp.lang.c)
  • Re: Who owns the variable in my header file ?
    ... to check the subscripts to the array and trap on error conditions. ... cast one type of pointer into another; you wouldn't then be able to step ... language trying to be C like, ... One reason being that the programmer can possible ...
    (comp.lang.c)
  • Re: why cannot assign to function call
    ... hypothetical C-like languages, ... sizeof business would still indicate that a pointer was being passed. ... talk about variables of an array type. ... the earlier version of the standard didn't have numbered ...
    (comp.lang.python)
  • Re: Pointer Equality for Different Array Objects
    ... Pointers to the same object are pointers to the same region of data storage. ... A pointer comaprison (for exact equality, ... we have the vague ("if the array is large enough"). ...
    (comp.lang.c)
  • Re: multi dimensional arrays as one dimension array
    ... please - where does the standard say that such a conversion ... Pointer conversion yields a pointer to the same object as ... exist only where there are array declarations. ...
    (comp.lang.c)