Mail Archives: djgpp/1999/08/27/01:07:07
----------
> From: Davin McCall <DavMac AT iname DOT com>
> To: djgpp AT delorie DOT com
> Subject: Re: Help with array of structures in which I will make an array
of one dimensional row pointers to...
> Date: Wednesday, August 25, 1999 9:05 AM
>
> On Thu, 26 Aug 1999 06:21:38 -0700, "Dan Gold" <TedMat AT CoastNet DOT com>
> wrote:
>
> >here we have my tile struct as it is so far:
> >
> >typedef struct TILE {
> > int type;
> > int src_x, src_y;
> >} TILE;
> >
> >Would a pointer to TILE point to the member "type" and add the offset
> >accordingly down the line as you reference the other members (meaning it
> >only used one 4 byte pointer) OR does it make 3 pointers each one to a
> >different member?
>
> Only one four-byte pointer. The other members, when they accessed, are
> done so by adding an offset to the pointer (this is done automatically
> by the compiler).
>
> >now If I allocate the data like so for all the tiles...
> >MAP * the_map;
> >the_map->dat = (TILE *)malloc(w * h * sizeof(TILE));
> >
> >And since I want to be able to reference the data like a two dimensional
> >array I need a bunch of line pointers to get the correct offset for the
> >start of each row. So I then add a TILE * tile[0]; member to the MAP
> >structure so I can dynamically allocate all the line pointers at run
time
> >when creating the memory for the MAP structure to hold the data as so
(this
> >is done before the allocation of TILE data ofcourse).
> >
> >the_map = (MAP *)malloc(sizeof(MAP) + (sizeof(TILE) * h));
> >
> >Now once I've assigned all the line pointers to the tile data at their
> >appropriote positions is I reference the tiles as:
> >the_map->tile[3][2]; // would the second array bracket offset by a TILE
> >meaning it would jump to the second tile.
>
> yes
>
> > Or would it offset the size of a
> >char like the line pointers in Allegro?
>
> This occurs because the line pointers are char pointers (or possibly
> void pointers).
>
> >. If they do offset to the next
> >tile, would it be faster to reference them by creating a pointer to
every
> >single TILE in the map data, considering the compiler would have to
offset
> >[2] with a multiplication of the size of TILE.
>
> Maybe, maybe not. The multiplication is not likely to cause a
> significant speed reduction so I wouldn't bother (especially as you
> will be saving memory, which can lead to speed increase in other ways,
> such as increased cache effectiveness).
>
> >Would compiler optimization change my struct to a size which could be
bit
> >shifted, by the column value for the address? Can you view compiler
> >optimized code with the -s extension when compiling?
>
> Not by itself, though I stress that it's not such an important issue.
> Incidentally the TILE structure you gave above would normally be of
> size 8 bytes, which is a shift-left by three.
>
> Davin.
>
> __________________________________________________________
When I run go32-v2.exe in dos, I get about 37mb virtual memory and 7.8 mb
of ram. Being that I have about 37mb free on my HD and 8mb of ram this
seems very good. In Windows I have less than 7mb virtual memory, and 3.7mb
of ram. I know Windows 95 takes about 4mb of my Ram but I don't know what
going on with the virtual memory. I know they have a section about this in
the FAQ and from what I remember you can do something to help this. I just
don't know how to change my DOS properties? I also have the Scitech display
doctor control icon in my Windows desktop loaded, if that takes anything.
You can tell by the way I'm speaking that I am no Windows Pro. I am
getting annoyed by running out of virtual memory on small programs, but the
strangest thing about it is that I think the virtual memory isn't being
free'd either, once I've used it. I read in the faq that this is a Windows
thing and I'm not using QUEMM, or CWSDPMI since that's only in DOS mode
from what I've read. Is this fixable?
Thanks for reading, ((--Dan Gold---))
- Raw text -