bson_performance man page

Performance_Notes — None

Array Element Key Building

When writing marshaling layers between higher level languages and Libbson, you will eventually need to build keys for array elements. Each element in a BSON array has a monotonic string key like 0 , 1 , etc. Using snprintf(3) and others tend to be rather slow on most libc implementations. Therefore, Libbson provides bson_uint32_to_string(3) to improve this. Using this function allows an internal fast path to be used for numbers less than 1000 which is the vast majority of arrays. If the key is larger than that, a fallback of snprintf(3) will be used.


char str[16];
const char *key;
uint32_t i;

for (i = 0; i < 10; i++) {
   bson_uint32_to_string (i, &key, str, sizeof str);
   printf ("Key: %s\n", key);

For more information, see bson_uint32_to_string(3)


This page is part of libbson. Please report any bugs at https://jira.mongodb.org/browse/CDRIVER.


Explore man page connections for bson_performance(3).