RE: RE: [Dev-C++] [Dev-C++]: Errors in structures
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Ioannis V. <no...@ya...> - 2001-07-04 13:17:27
|
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Johannes
Pretorius
Sent: Wednesday, July 04, 2001 7:08 AM
To: dev...@li...
Cc: dev...@li...
Subject: Fwd: RE: [Dev-C++] [Dev-C++]: Errors in structures
>
>Please for give if I am incorrect but does a union not allocate the=20
>memory
>space
>of the biggest type inside it. for instace in your example the biggest=20
>type is the Align (I think) so the whole
>union will be that size. Note that a union enables varaibles to share a
I had ommitted a line. Also i will put all he comments and say some
lines of the book.
The code is:
typedef long Align /* For allignment att the limits of long */
union header /* The header of the block */
{
struct
{
union header *ptr; /* next block if it is in the list */
unsigned size; /* size of the block
}s;
Align x; /* Imposition of the allignment of blocks */
};
typedef union header Header;
"A free block contains one pointer to the next block of the chain, one
record for the size of the block, and then the free space itself. The
information for control at the beginning, is called "header". For the
allignment to be simplified, all blocks are multiples of the header
size, and the header is properly alligned. This is achieved with one
union which contains the desired structure of the header and one case of
the most restrictive type of alignment, which we have chosen here
arbitrarily as long".
Also it has a graphic showing some stuff.
------------> points at the next free block
|
----------------------------------
| | | |
| | size| |
----------------------------------
|
------------> The address returned to user (in the book
from malloc()).
So the memory used for non built in types are multiples of these blocks.
If anyone knows more i would be happy to learn what he knows....
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.f2s.com
* Alternative URL: http://run.to/noicys
|