API : constness ?

Isaac To kkto at csis.hku.hk
Tue Jun 1 02:45:09 EDT 2004


>>>>> "Tim" == Tim Roberts <timr at probo.com> writes:

    >>>> static const char * const kwlist[] = { "uri", "open_mode",
    >>>> "exclusive", "perm", NULL };
    >>>  Does this give any performance or size improvement?

    Tim> The data MAY be in a read-only segment,

The strings like "uri", "open_mode", etc., are in read-only segment anyway,
whether you add the "const" or not.  On the other hand, kwlist cannot be in
read-only segment, no matter you add "const" or not, since they are
initialized not when you compile the module, but instead when you load the
module (see below).  Initialization at load time means modification of the
memory location.  Since the memory need to be modified (once, at load time),
they cannot be mapped to memory from file directly, and accordingly they
cannot be in read-only memory.

    Tim> but even assuming that it is, that doesn't do anything to reduce
    Tim> relocation or load time.

This is absolutely correct.  It is simply impossible to make relocations
unnecessary, because the char* pointers stored in kwlist must point to the
absolute addresses of the static strings, which cannot be determined until
the python program actually loads the module (because, until then, we won't
be able to tell what part of the address space is available).

Regards,
Isaac.



More information about the Python-list mailing list