For -AA Standard Library

The following 4 defines can change the container initial allocation and growth ratio:

For an arbitrary container type:

#define _RWSTD_MINIMUM_NEW_CAPACITY size_t(32)

#define _RWSTD_NEW_CAPACITY_RATIO float(1.618)

For a string type:

#define _RWSTD_MINIMUM_STRING_CAPACITY size_t(128)

#define _RWSTD_STRING_CAPACITY_RATIO float(1.618)

For more precise control of containers, the following explicit specialization can be used.

The namespace scope functiontemplate __rw can be explicitly specialized to return the current size in elements of any container.

template <>

inline size_t __rw_new_capacity (size_t __size, const _Container*)

The parameters passed in are the current size in elements and the container's pointer. The default behavior results in an amortized constant time algorithm that dramatically increases rapidity while retaining a regard for space efficiency.

The defaults have been tuned with speed versus space optimization of container performance with regard to allocation of memory.

The ratio parameter must be above 1 for an amortized constant time algorithm. Lowering the ratio will lower rapidity and improve space efficiency. This effect will be most noticable when working with containers of few elements (less than 32).

The following is a container allocation example for both the -AP and -AA Standard library:

#include

namespace std {} using namespace std; #include

#include #define NUM 4

int printMallocInfo(const char*); #ifndef DEFAULT

//specialize default size

//Default buffer size for containers. #ifdef _HP_NAMESPACE_STD

namespace __rw { template <>

inline size_t __rw_new_capacity(size_t __size, const list*) { printf("......\n");

//if small grow by 5, else by 1/8 current size

return __size < 100 ? 5 : __size / 8;

}

}

#else // -AP template <>

inline size_t __rw_allocation_size(int*, size_t) { printf("......\n");

return sizeof(int) >= 1024 ? 1 : 5;

}

#endif // -AA #endif // DEFAULT int main() {

int count = 0;

list *tryit; for (int i = 0;ipush_back(i); printMallocInfo("1st entry added"); tryit->push_back(i + 1); printMallocInfo("2nd entry added"); count++;

}

printMallocInfo("at end");

Creating and Using Libraries 185

Page 185
Image 185
HP C/aC++ for PA-RISC Software manual For -AA Standard Library, For a string type