[aclug-L] C/C++ question
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
This is some code I found on Bruno Preiss's Algorithms
site:
----
class BuddyPool : public StoragePool
{
public:
enum Status { free, reserved };
struct Header
{
Status status: 1;
unsigned int k : bitsizeof (unsigned int) - 1U;
};
struct Block : public Header
{
enum { size = 16 };
struct Links
{
Block* next;
Block* prev;
};
union
{
Links link;
char userPart [size - sizeof (Header)];
};
};
...
---
It's for memory allocation. I'm confused about what
the
enum { size = 16 };
is doing. Is this just declaring a constant size to be
16 inside the struct so you don't have to declare it
16 outside later? If so, size is a real member of the
struct Block and will take up memory, it's just that
it already has a value--or am I seeing this wrong?
I'm also trying to figure out what this Block struct
will look like in memory if I allocate dynamic memory
for it, e.g., what is happening with the struct Links
declaration? Does it always get included since it's
embedded, or is it left out when the Links link is not
used (i.e., if a constructor doesn't utilize it)? The
book seems to be saying that because of the union, it
should just have the Header stuff and the char
userPart if the *next/*prev pointers aren't asked for
by a constructor--all for the lightest memory
footprint possible. Any enlightenment appreciated....
LB
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-- This is the discussion@xxxxxxxxx list. To unsubscribe,
visit http://www.complete.org/cgi-bin/listargate-aclug.cgi
- [aclug-L] Re: Win4Lin Pro, Ryan, 2006/03/01
- [aclug-L] Re: Win4Lin Pro, Olwe Bottorff, 2006/03/01
- [aclug-L] Re: Win4Lin Pro, Ryan, 2006/03/01
- [aclug-L] Re: Win4Lin Pro, Jeff Vian, 2006/03/01
- [aclug-L] C questions, Olwe Bottorff, 2006/03/12
- [aclug-L] Re: C questions, Jonathan Hall, 2006/03/12
- [aclug-L] Re: C questions, Olwe Bottorff, 2006/03/12
- [aclug-L] Re: C questions, Tom Hull, 2006/03/12
- [aclug-L] Re: C questions, Jonathan Hall, 2006/03/12
- [aclug-L] C/C++ question,
Olwe Bottorff <=
- [aclug-L] Re: C/C++ question, Tom Hull, 2006/03/28
|
|