I'm using a bit vector to detect circular references. Currently this is coded as:
## Scalar will always be quad aligned and have ## a mimimum size of 12 bytes. return 'SELFREF' if vec( $circ, $addr / 12, 1 ); vec( $circ, $addr / 12, 1 ) = 1;
Three questions arise:
According to PerlGuts Illustrated SvNULL is the simplest (smallest) SV that can be allocated--which is where the / 12 comes from above.
Most SV structures are greater than 12 bytes, and I could reduce the overhead commensurately if (for example) there was only ever one SvNULL allocated in the system and all other SV's were multiples of 16 or 20 bytes?
Also, many alloc() functions actually allocate an extra word or two at the front or end of a memory allocation for integrity checking. If I could include those words in the count I could further reduce the length of the bit vector?
As it currently stands, the maximum overhead for the bit vector is 43 MB for a 32-bit processor that can address 4 GB of ram. This is okay, and in most instances will be much less, but if I could also figure out (at runtime) the fixed amount of memory allocated by the Perl process before the user program is interpreted, I could subtract that amount from the addresses and factor out the start of the bit vector.
Likewise, as the code will be called as a function, if I could determine the current end-of-heap value, I could pre-allocate the bit-vector and prevent it from causing allocations on the fly as it discovers new, higher addresses.
In reply to Circular reference testing. by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |