Guardian Programmer's Guide

Table Of Contents
Mixed Data Model Programming
Guardian Programmer’s Guide 421922-014
A - 7
Examples
C Example:
#include <kmem.h> nolist
#include <kpool64.h> nolist
#include <stdio.h> nolist
#include <string.h> nolist
#include <cextdecs(FILE_WRITE64_)> nolist
#include <unistd.h> nolist
int main( void ) {
void _ptr64 * segment; /* Base address of the 64-bit Segment */
short err, detail; /* Results from SEGMENT_ALLOCATE64_ */
uint32 error; /* Results from POOL64 functions */
NSK_POOL64_PTR pool_ptr; /* 64-bit Pool Header */
void _ptr64 * ptr; /* Buffer allocated from the pool */
int64 poolSize = 1024LL * 1024 * 1024;
/* Allocate the 64-bit Segment */
err = SEGMENT_ALLOCATE64_( 1
, poolSize
, /* filename */ , /* filename length */
, &detail
, /* pin */
, /* segment-type (default) */
, &segment
);
if ( err != SEGMENT_OK ) {
fprintf( stderr, "Error %d,%d returned by SEGMENT_ALLOCATE64_\n",
err, detail);
return 1;
}
/* Set address of pool */
pool_ptr = (NSK_POOL64_PTR)segment;
/* Define the pool */
error = POOL64_DEFINE_( pool_ptr, poolSize, POOL64Default );
if ( error != POOL64_OK ) {
fprintf( stderr, "Error %d returned by POOL64_DEFINE_\n" , error );
return 1;
}
/* Allocate a buffer from the pool */
ptr = POOL64_GET_( pool_ptr, 100 , &error );
if ( error != POOL64_OK ) {
fprintf( stderr, "Error %d returned by POOL64_GET_\n" , error );
return 1;
}
/* Copy data to be written into the pool */
strcpy64( (char _ptr64 *)ptr, "This data is in a 64-bit segment" );
/* Write the Data to Standard Out */
FILE_WRITE64_( STDOUT_FILENO,
(char _ptr64 *)ptr,
(int)strlen64( (char _ptr64 *)ptr )
);
return 0;
}