Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX 11i Version 1.5 Release Notes: release id B.11.20for rx9610 and rx4610 hp serversand i2000 hp workstations > Chapter 7 Programming

Changes to libc

» 

Technical documentation

Complete book in PDF
» Feedback
Content starts here

 » Table of Contents

 » Index

libc.a Obsolesence

libc.a is not available for native IPF development. Applications which explicitly link to libc.a will fail. This change affects makefile compatibility, makefiles which explicitly link to libc.a using

  • +A (aCC)

  • -aarchive (ld)

  • -Wl,-aarchive (compilers)

  • -noshared (ld, compilers)

  • -l:libc.a (ld)

  • -Wl,-l:libc.a (compilers)

should be modified.

Libc Floating-Point Conversion

The libc routines that convert between decimal strings representing floating-point numbers, and internal binary floating-point formats were changed for HP-UX 11i Version 1.5 (B.11.20).

When compiled with the -fpwidetypes option, the HP-UX 11i Version 1.5 (B.11.20) <stdlib.h> header defines two new types:

typedef __float128 quad;
typedef __float80 extended;

quad is a synonym for long double; it is the 128-bit IEEE-754 floating type supported on PA systems. extended is the 80-bit IEEE-754 double-extended type in the Itanium architecture. The definitions, which also appear in the <math.h>, <float.h>, and <complex.h> headers, are protected by __ia64 and _INCLUDE_HPUX_SOURCE switches. To use these type names for other purposes, you should undefine them (with #undef) after inclusion of the above headers.

The HP-UX 11i Version 1.5 (B.11.20) <stdlib.h> header, under the ia64 and _PROTOTYPE switches, defines the long_double type to be the true "long double" type supported by the compiler. In previous releases, long_double was defined to be a struct. A program which requires the struct definition can be compiled with the -Ac option (the default prior to HP-UX 11.0), or, alternatively, with -D_LONG_DOUBLE_STRUCT added to the compile command.

The HP-UX 11i Version 1.5 (B.11.20) <stdlib.h> header, under the __ia64 and _INCLUDE_HPUX_SOURCE switches, declares the new function:

extern float strtof(const char *, char **);

and, when compiled with the -fpwidetypes options, also declares these new functions:

extern __float128 strtoq(const char *, char **);
extern __float80 strtow(const char *, char **);
extern char *_extecvt(__float80, int, int *, int *);
extern char *_extfcvt(__float80, int, int *, int *);
extern int _extecvt_r(__float80, int, int *, int *, char *, int);
extern int _extfcvt_r(__float80, int, int *, int *, char *, int);

all of which are defined in libc.

  • strtoq() is equivalent to strtold()

  • strtof() and strtow() are float and extended (80-bit floating-point) versions, respectively, of strtod()

  • _extecvt(), _extfcvt(), and _extgcvt() are extended versions of ecvt(), fcvt(), and gcvt() respectively

  • _extecvt_r() and _extfcvt_r() are extended versions of the reentrant ecvt_r() and fcvt_r() respectively

The routines which convert between decimal strings representing floating-point numbers and internal binary floating-point formats are correctly rounded according to the specification in ISO/IEC C99, to 36 significant decimal digits. (36 is the smallest number of digits that will distinguish all the numeric values in the 128-bit long double type.) Corresponding HP-UX 11i routines do not round correctly to the last bit or digit in all cases. The HP-UX 11i Version 1.5 (B.11.20) binary-to-decimal conversion (used by printf) produces zeros after the 36th significant digit, for all floating-point precisions; this differs from the HP-UX 11i conversion which produces zeros after the 17th significant digit in double and after the 33rd significant digit in long double.

The long double strtold function for overflow cases returns the value HUGE_VALL (defined to be +infinity in <math.h>), with the appropriate sign. This follows the ISO/IEC C99 specification, and is analogous to strtod(), which returns HUGE_VAL (also equal to +infinity), with the appropriate sign. On HP-UX 11.0 and 11i, strtold() for overflow cases returns _LDBL_MAX or _LDBL_NMAX (defined in <values.h>), depending on the sign of the value; these are the largest-magnitude finite long double values.

All the HP-UX 11i Version 1.5 (B.11.20) *cvt functions (double, extended, and long double) treat NaNs and infinities the same way, and that way is consistent with the HP-UX 11i double [efg]cvt functions: they return ++ and -- for +infinity and -infinity, and they return [-]? for NaNs. On HP-UX 11i, the long double _ld[efg]cvt functions return +INFINITY and -INFINITY for +infinity and -infinity, and they return [-]NaN for NaNs.

New Environment Variables and Defaults for malloc()

In earlier versions of libc on PA, libc used a single lock in the malloc routines to make them thread-safe. In a multi-threaded application, there could be contention on this single lock if multiple threads are calling malloc and free at the same time. On HP-UX 11i Version 1.5 (B.11.20), libc provides multiple arenas, where malloc can allocate space from, and a lock for each arena. Threads are distributed among the arenas. Two new environment variables are introduced:

_M_ARENA_OPTS
_M_SBA_OPTS

_M_ARENA_OPTS can be used to tune the number of arenas and the arena expansion factor for threaded applications. In general, the more threads in an application, the more arenas should be used for better performance. Expansion factors control the number of pages to expand each time and assumes the page size is 4096 bytes. The number of arenas can be from 1 to 64 for threaded applications. (For non-threaded applications, only one arena is used regardless of whether this environment variable is set or not. However, you still can use this environment variable to change the expansion factor for non-threaded applications). If the environment variable is not set, or the number of arenas is set to be out of the range, the default number of 8 is used. The expansion factor is from 1 to 4096; the default value is 32. Again, if the factor is out of the range, the default value will be used. For example:

$ export _M_ARENA_OPTS=8:32

where the number of arenas is 8, and the expansion size is 32*4096 bytes. In general, the more arenas you use, the smaller the expansion factor should be, and vice versa.

Beginning in HP-UX 11i Version 1.5 (B.11.20), for Itanium-based systems only, the small block allocator is active by default with the following configuration: __maxfast = 512, num_smallblocks = 100, grain = 16. The default for num_smallblocks is unchanged from PA systems and the SVID 3 default. The default for grain is the default alignment for Itanium-based systems (16), which is the smallest grain allowable given that small blocks must have at least the default alignment. This requirement in turn comes from the standards requirement that malloc() must always return an address suitably aligned for any basic data type, and Itanium-based systems support 16-byte basic data types.

The new default for __maxfast is 512, which is changed from 0 on PA systems. This means that the SBA is now active by default, rather than inactive by default, as was and remains the case for PA systems.

Three exported integer variables have been added for IPF:

int __hp_malloc_maxfast;
int __hp_malloc_grain;
int __hp_malloc_num_smallblocks;

These three variables may be set by applications to override the SBA defaults; e.g. if an application links to a module that defines

int __hp_malloc_maxfast = -1;

then the value -1 will be seen for __hp_malloc_maxfast when the function __get_sba_global() is called. The -1 value for __hp_malloc_maxfast means that the SBA should be turned off, i.e. __maxfast will be set to 0. A positive value for __hp_malloc_maxfast will replace the default value of __maxfast after rounding to a multiple of the grain. Positive values for the variables __hp_malloc_grain and __hp_malloc_num_smallblocks will be used to replace the grain and num_smallblocks values if the resulting values would be legal.

These global variables override the environment variable _M_SBA_OPTS. It is presumed that any ISV that builds an application so that these variables are set wants that tuning and no other. However, subsequent mallopt() calls will revise the values for SBA configuration if the SBA has not yet been allocated. (In the same way that mallopt() calls will revise the SBA configuration even when the environment variable _M_SBA_OPTS has been set if the SBA has not yet been allocated at the time of the mallopt() calls.)

_M_SBA_OPTS turns on the small block allocator, and sets up parameters for the small block allocator, namely, maxfast, grain, num_smallblocks. Refer to mallopt() for details about the small block allocator, and its parameters. Applications with a small block allocator turned on usually run faster than with it turned off.

A small block allocator can be turned on through mallopt(); however, it is not early enough for C++/Java applications. The environment variable turns it on before the application starts.

mallopt() call can still be used the same way. If the environment variable is set, and no small block allocator has been used, the subsequent mallopt() calls can still overwrite whatever is set through _M_SBA_OPTS. If the environment variable is set, and a small block allocator has been used, then mallopt() will have no effect. For example:

$ export _M_SBA_OPTS=512:100:16

where the maxfast size is 512, the number of small blocks is 100, and the grain size is 16. You must supply all 3 values, and in that order. If not, the default ones will be used instead.

The _M_ARENA_OPTS and _M_SBA_OPTS environment variables have the following impact:

  • Performance is improved for multi-threaded applications.

  • Threaded applications may experience increased heap storage usage but you can adjust the heap usage through _M_ARENA_OPTS.

NOTE: Threaded applications which are linked with archive libc and other shared libraries where those shared libraries have dependencies on shared libc may break.

New malloc family API

The new API, memalign(), has been added to the malloc family. See the memalign(3C) manual page for details.

Changes to confstr()

HP-UX 11i Version 1.5 (B.11.20) includes an enhanced version of confstr() that defines three new parameter values.

_CS_MACHINE_IDENT

ID number for each physical machine. Returned as an opaque string of printable ascii characters not to exceed 64 bytes including the string terminator. This string has the same value for all partitions in a physical machine. For hardware classes first released with HP-UX 11i Version 1.5 (B.11.20) or later this ID number is unique across all hardware classes. For earlier hardware classes the ID number is unique only within the hardware class. A null string is returned if no ID number is available (expected to be the case only for prototype machines or others improperly configured in manufacturing).

_CS_PARTITION_IDENT

ID number for each partition existing on a machine. Returned as an opaque string of printable ascii characters not to exceed 64 bytes including the string terminator. For any machine not supporting partitions this value will be the same as _CS_MACHINE_IDENT.

_CS_MACHINE_SERIAL

machine serial number as found labeled on the external machine chassis. The value will be a printable ascii string not to exceed 64 bytes including the string terminator. This string is not available on all classes of machines; if unavailable, the string will be empty. This string is not a unique identifier of the machine, since machines of different classes can have the same serial number. If a unique identifier is needed, use _CS_MACHINE_IDENT or _CS_PARTITION_IDENT.

The preferred method of calling these functions is defined in the confstr(3C) manpage as:

bufsize=confstr(_CS_MACHINE_IDENT,NULL,(size_t)0);
buffer=(char *)malloc(bufsize+1);
confstr(_CS_MACHINE_IDENT,buffer,bufsize+1);

The first line will return the length of the string to be returned, allocate memory based on this value, then call confstr() again to get the actual value.

For more information, see “Changes to Machine Identification” in Chapter 3 “HP-UX Features” and the confstr(3C) manual page.

Locale Names

HP-UX 9.x locale names are no longer supported.

Linux compatibility

The linux compatibility interfaces, getresgid() and getresuid() have been added to libc. These functions return the real, effective, and saved gids and uids, respectively. See the getresgid(3C) and getresuid(3C) manual pages for more details.

libc Documentation

For more information about these changes, see

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 2001 Hewlett-Packard Development Company, L.P.