Re: contiguity of arrays

From: Wojtek Lerch (Wojtek_L_at_yahoo.ca)
Date: 10/04/04


Date: Sun, 3 Oct 2004 23:29:13 -0400


"David Hopwood" <david.nospam.hopwood@blueyonder.co.uk> wrote in message
news:C7L7d.185576$hZ3.39917@fe2.news.blueyonder.co.uk...
> Wojtek Lerch wrote:
>> What you seem to be saying is that for a region of memory to constitute
>> an array of four ints, it doesn't have to be declared with a type that
>> involves an array of four ints, or designated by an lvalue with such a
>> type, but nevertheless it must be declared with some aggregate type
>> ultimately consisting of four ints and no padding bytes between them.
>
> Yes. This view is based on the definition of "array type" as being the
> type
> of any contiguous nonempty sequence of objects of the element type. In
> order

Not just *any* contiguos sequence. A struct type that consists of four ints
and turns out to have no padding bytes is not an array type. It's a struct
type.

> to perform an access via a given pointer, say of type T, you need to be
> able
> to infer that it currently points to a region that *can* hold an object of
> type T. The memory allocation functions are a special case that return
> pointers to regions able to hold objects of any type.

That is not a very accurate wording: regions of memory don't hold objects,
they are objects. An allocated object can be given any effective type by
using an lvalue of that type to store a value in the object. But when it
has an effective type, it's one type. When it's a struct, it's not an array
of int.

>> But, I presume, possibly with some extra stuff after the four ints. Is
>> that more or less correct? Do you have a way of describing it that
>> doesn't feel arbitrary and inconsistent?...
>
> Not particularly. It would help if the definitions of "object", "array"
> etc.
> in the standard were clearer.



Relevant Pages

  • Re: implementing an array based class
    ... Memory profiling turns out to be kind of a pain to get going. ... A struct is really nice and easy to ... I made an array of about 500,000 arrays. ... class MyObject < Array ...
    (comp.lang.ruby)
  • Re: "Parallel.For GC problems" and a solution.
    ... I think Dictionary(of dictionary(of small array of ints)) ... with the dictionaries holding arrays of keys, ... do not pass it a large array of things to process. ... With no breaks, memory goes crazy. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: nonhomogenous structs (was: lisp performance questions and observations)
    ... ints ... naturally represented as an array of structs, ... So actually, I don't care about the mixture between bytes, longs, ... machine words for each struct before I even get to the "data" for the ...
    (comp.lang.lisp)
  • Re: static aray question?
    ... typedef struct i{ ... Once the f1function is executed, the static array xwill always live ... Whether it remains in memory or gets swapped to ... I also get the following warning saying that g is uninnitialized. ...
    (microsoft.public.vc.language)
  • Re: void * C array to a Numpy array using Swig
    ... SWIG to return the data as a string in python. ... converted to a numpy array using the fromstring function. ... returns the data into memory that the user has to malloc. ... a pointer to your struct as argument, the first returns the size of the ...
    (comp.lang.python)