1XS(3) User Contributed Perl Documentation XS(3)
2
3
4
6 Readonly::XS - Companion module for Readonly.pm, to speed up read-only
7 scalar variables.
8
10 This document describes version 1.04 of Readonly::XS, December 6, 2005.
11
13 Install this module, but do not use it.
14
16 The Readonly module (q.v.) is an effective way to create non-modifiable
17 variables. However, it's relatively slow.
18
19 The reason it's slow is that is implements the read-only-ness of vari‐
20 ables via tied objects. This mechanism is inherently slow. Perl sim‐
21 ply has to do a lot of work under the hood to make tied variables work.
22
23 This module corrects the speed problem, at least with respect to scalar
24 variables. When Readonly::XS is installed, Readonly uses it to access
25 the internals of scalar variables. Instead of creating a scalar vari‐
26 able object and tying it, Readonly simply flips the SvREADONLY bit in
27 the scalar's FLAGS structure.
28
29 Readonly arrays and hashes are not sped up by this, since the SvREAD‐
30 ONLY flag only works for scalars. Arrays and hashes always use the tie
31 interface.
32
33 Why implement this as a separate module? Because not everyone can use
34 XS. Not everyone has a C compiler. Also, installations with a stati‐
35 cally-linked perl may not want to recompile their perl binary just for
36 this module. Rather than render Readonly.pm useless for
37 these people, the XS portion was put into a separate module.
38
39 Programs that you write do not need to know whether Readonly::XS is
40 installed or not. They should just "use Readonly" and let Readonly
41 worry about whether or not it can use XS. If the Readonly::XS is
42 present, Readonly will be faster. If not, it won't. Either way, it
43 will still work, and your code will not have to change.
44
45 Your program can check whether Readonly.pm is using XS or not by exam‐
46 ining the $Readonly::XSokay variable. It will be true if the XS module
47 was found and is being used. Please do not change this variable.
48
49 EXPORTS
50
51 None.
52
54 Readonly.pm
55
57 Eric Roode, roode@cpan.org
58
59 Copyright (c) 2003-2005 by Eric J. Roode. All Rights Reserved. This
60 module is free software; you can redistribute it and/or modify it under
61 the same terms as Perl itself.
62
63 To avoid my spam filter, please include "Perl", "module", or this mod‐
64 ule's name in the message's subject line, and/or GPG-sign your message.
65
66
67
68perl v5.8.8 2005-12-06 XS(3)