0

C function void *__cdecl malloc(size_t _Size); and C++ template class template < class T, size_t N > class array; both mention the type size_t.

int *p = (int*)malloc(6*sizeof(int)); statement allocates a memory of 6*sizeof(int) bytes.

However, array<int, 6*sizeof(int)> myArray; statement allocates a memory of 6*sizeof(int)*sizeof(int) bytes.

I want to know if the first size_t have the same meaning with the second size_t.

Gerhardh
  • 11,688
  • 4
  • 17
  • 39
  • https://stackoverflow.com/questions/1951519/when-to-use-stdsize-t and https://stackoverflow.com/questions/131803/unsigned-int-vs-size-t pretty much cover it. – Retired Ninja Aug 30 '20 at 03:15
  • 2
    Type `size_t` itself does not speak to the significance of values of that type any more than type `int` speaks to the significance of `int`s. `size_t` is wide enough to represent the size, in bytes, of any object, including array objects, but that does not in any way mean that `size_t` values must be such object sizes. – John Bollinger Aug 30 '20 at 03:22
  • `std::size_t` is the type returned by `sizeof`. It is defined in 7 header files. More info: [std::size_t](https://en.cppreference.com/w/cpp/types/size_t). – Eljay Aug 30 '20 at 12:07

0 Answers0