[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Pointer question about Discrete2d
From: |
Tom Wainwright |
Subject: |
Re: Pointer question about Discrete2d |
Date: |
Thu, 05 Apr 2001 08:45:00 -0700 |
Paul E Johnson wrote:
>
> There is a pointer usage in swarm, src/space/Discrete2d.m, that I don't
> understand.
>
> Discrete2d.h declares
> long * offsets;
Here, "offsets" is a "pointer to long", so "*offsets" is a "long".
>
> It is allocated in Discrete2d.m
>
> - makeOffsets
> {
> unsigned i;
> // precalculate offsets based on the y coordinate. This lets
> // us avoid arbitrary multiplication in array lookup.
> offsets = [getZone (self) alloc: ysize * sizeof (*offsets)];
> for (i = 0; i < ysize; i++)
> offsets[i] = xsize * i; // cache this multipliction
> return self;
> }
>
> I don't understand why the aloc is not
> offsets = [getZone (self) alloc: ysize * sizeof (long)];
>
> I don't get what sizeof(*offsets) means.
As "*offsets" is declared as a long in the header, sizeof(*offets) will
return the size of a long. This notation just makes sure that the
allocation will match the declared type of "offsets", otherwise a coder
might change the declaration in the header, but not the allocation size
here.
>
> Can someone explain for a poor, old country doctor?
Hope this makes sense.
--
Tom Wainwright
NOAA/NMFS/NWFSC
2030 S Marine Science Dr
Newport, OR 97365 USA
address@hidden
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.