dummy (or not) question about AllocateWindow ()

Adam Jackson ajax at nwnk.net
Mon Jun 26 08:05:09 PDT 2006

On Sunday 25 June 2006 09:44, Carlos Eduardo Rodrigues Diógenes wrote:
> On Fri, 2006-06-23 at 11:25 -0400, Adam Jackson wrote:
> > (pWin + 1) evaluates first.  pWin is a pointer; pointer arithmetic works
> > like arrays, incrementing a pointer gives you a pointer to the memory
> > just after the object (struct, union, or primitive type) originally
> > pointed to.
> Thanks for the explanation, but I'm still in troubles with this ;-).
> pWin points to a region of the size pScreen->totalWindowSize, that can
> be bigger than the Window structure or not. So (pWin + 1) can't make
> ppriv points to an incorrect memory position?

totalWindowSize is guaranteed to be no smaller than sizeof(WindowRec).  It is 
initially sized to be exactly that large (plus padding out to the nearest 
multiple of sizeof(long)) in dix/main.c, and then sizeof(DevUnion) is added 
to it in dix/privates.c, so when you allocate totalWindowSize bytes, you're 
allocating enough for both a WindowRec and a DevUnion.  The funny pointer 
math is just getting you to the DevUnion at the end.

- ajax
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg/attachments/20060626/c77583c7/attachment.pgp>

More information about the xorg mailing list