0

My understanding is that size_t is a type large enough to represent (or address) any memory position in a given architecture. For instance, on a 32 bit machine size_t should be able to represent at least 2^32 values. This means that sizeof(size_t) must be >= 4 in 32 bit architectures, right?

So what should be the sizeof(size_t) on code that's meant to run a gpu?

Since many gpus have more than 4gb, sizeof(size_t) must be at least 5. But I imagine it's 8, for alignment purposes.

Trauer
  • 1,981
  • 2
  • 18
  • 40
  • Does this answer your question? [What is size\_t in C?](https://stackoverflow.com/questions/2550774/what-is-size-t-in-c) – radrow Mar 21 '22 at 10:40

1 Answers1

1

Roughly speaking, size_t should be able to represent the size of any single allocated object. This might be smaller than the total address space though.

For example in 16-bit MS-DOS program one memory model had a 16-bit size_t even though many megabytes of memory were available, and pointers were 32-bit. But you could not allocate any particular chunk of memory larger than 64K.

It would be up to the compiler writer for the GPU to make size_t have some size that is large enough for the largest possible allocation on that GPU. As you say, this is likely to be a power of 2 (but not guaranteed).

The type used to represent any memory position is void *.

M.M
  • 138,810
  • 21
  • 208
  • 365