Fixing devPrivates

Keith Packard keithp at keithp.com
Thu Apr 29 23:21:59 PDT 2010


On Fri, 30 Apr 2010 04:45:43 +0200, Tomas Carnecky <tom at dbservice.com> wrote:

> Is there any other reason you chose to allocated the array only once
> when the object is created?

For almost all of the objects, the privates are allocated along with the
underlying object itself, saving an allocation call and keeping memory
accesses more local. The one exception is the screen object where
privates are added on the fly during server initialization, requiring a
realloc call.

Without a separate allocation, it would be tricky to reallocate the
private storage. This is precisely how privates worked when first
implemented, so we aren't inventing a new requirement, just enforcing it
again after a short hiatus.

> Another difference, albeit a minor one, was that I kept my 
> 'DevPrivateRec' structures allocated inside privates.c instead of 
> scattered around the source files.

Having them defined in the individual source file makes the privates
code simpler; it doesn't need to allocate anything as they are
registered. Plus, it means that getting the offset requires only a
single memory fetch instead of two.

> That allowed me to easily dump statistics about which privates are
> used in which objects etc. I thought that would be a useful feature
> for debugging purposes, or to simply see how much memory is being used
> where.

The privates code has a list of every key used everywhere once the
server starts, and I've got some statistics dumping code written for
precisely this purpose.

-- 
keith.packard at intel.com
-------------- 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-devel/attachments/20100429/b37d15bf/attachment.pgp>


More information about the xorg-devel mailing list