Chapter 8
The first parameter is an  id  used to detect memory leaks; unless you're doing 
memory debugging, you can safely use zero. The second parameter can be used to 
preallocate memory inside the SV for strings. If you know you'll be using the SV to 
hold a large string, then you can potentially improve performance by preallocating 
the space.
In practice, NEWSV is rarely used. This is because the Perl API supplies conve 
nience functions to create SVs directly from the available value types:
SV *sv_iv, *sv_uv, *sv_nv, *sv_pv;
sv_iv = newSViv( 10);       // sv_iv contains the signed integer value  10
sv_uv = newSVuv(10);        // sv_uv contains the unsigned integer value 10
sv_nv = newSVnv(10.5);      // sv_nv contains the floating point value 10.5
sv_pv = newSVpv("ten", 0);  // sv_pv contains the string "ten", the second
                            // parameter tells Perl to compute the length with
                            // strlen()
A more efficient version of newSVpv() called newSVpvn() doesn't offer automatic 
strlen() calling:
sv_pv = newSVpvn("ten", 3);  // second parameter gives the length of "ten"
A version that uses sprintf() style format strings, newSVpvf(), is also available:
sv_pv = newSVpvf("%d", 10);  // sv_pv contains the string "10"
NOTE The comments used in the C examples are actually C++ style 
comments (// comment). This was done to improve readability and 
reduce the space required by the comments. Most modern C compilers 
will accept these comments, but if yours doesn't you'll need to change 
them to C style comments (/* comment */) or omit them entirely.
Type Checking
You can test the type of an SV using the SV*OK macros. Specific versions exist for the 
specific types:
if (SvIOK_notUV(sv)) warn("sv contains an IV.");
if (SvIOK_UV(sv))    warn("sv contains a UV.");
if (SvNOK(sv))       warn("sv contains an NV.");
if (SvPOK(sv))       warn("sv contains a PV.");
178






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

web hosting perl

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved