In this example, we're emulating a function that stores arbitrary data in a file or a database. The function accepts a pointer to the data and data size. But what type should we use to represent the size? If we use an unsigned int in a 64-bit system, we're artificially limiting the capability of our function to handle only up to 4 GB of data.
To avoid such limitations, we use size_t as a data type for size:
void StoreData(const char* buffer, size_t size) {
Most standard library APIs that accept indices and sizes also deal with size_t parameters. For example, the memcpy C function, which copies a chunk of data from the source buffer to the destination buffer, is declared as follows:
void *memset(void *b, int c, size_t len);
Running the preceding code produces the following output:
As we can see, the size of the pointer on the target system is 64-bit, despite the size of int being 32-bit. Using size_t in our program allows it to use all the memory of the embedded board.