473,326 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

std::size_t

can someone refresh my meory on what std::size_t is used for? I am wondering
if my template container class should have it's capacity as a size_t or an
int?
,
Christopher
Jul 22 '05 #1
5 6161
"Christopher" <cp***@austin.rr.com> wrote...
can someone refresh my meory on what std::size_t is used for? I am wondering if my template container class should have it's capacity as a size_t or an
int?


std::size_t is a type of the value returned by 'sizeof' operator.
std::size_t is a type in which a size of an array is measured. It
is the type of the argument to the allocation function (used with
'new', for example). It comes from C, defined in <cstddef> header.

Victor
Jul 22 '05 #2
Christopher wrote:
can someone refresh my meory on what std::size_t is used for? I am wondering
if my template container class should have it's capacity as a size_t or an
int?


'size_t' ('std::size_t') is a type that can be used to hold a size of
any object in C/C++ program. Since an array in C/C++ is an object
itself, this type can also be used to store the size of an array. But in
generic case the concepts of "object size" and "container size" are
orthogonal and this type should not be used to store the size of a
container (number of elements).

--
Best regards,
Andrey Tarasevich

Jul 22 '05 #3
Andrey Tarasevich wrote:
Christopher wrote:
can someone refresh my meory on what std::size_t is used for? I am wondering
if my template container class should have it's capacity as a size_t or an
int?

'size_t' ('std::size_t') is a type that can be used to hold a size of
any object in C/C++ program. Since an array in C/C++ is an object
itself, this type can also be used to store the size of an array. But in
generic case the concepts of "object size" and "container size" are
orthogonal and this type should not be used to store the size of a
container (number of elements).

Why?
And who says?
And what to use instead?

marc

Jul 22 '05 #4
"Marc Schellens" <m_*********@hotmail.com> wrote in message
news:3F**************@hotmail.com...
Andrey Tarasevich wrote:
Christopher wrote:
can someone refresh my meory on what std::size_t is used for? I am wonderingif my template container class should have it's capacity as a size_t or anint?

'size_t' ('std::size_t') is a type that can be used to hold a size of
any object in C/C++ program. Since an array in C/C++ is an object
itself, this type can also be used to store the size of an array. But in
generic case the concepts of "object size" and "container size" are
orthogonal and this type should not be used to store the size of a
container (number of elements).

Why?


Because there's no clear requirement that all the elements of the
sequence controlled by a container have to fit in memory at the
same time.
And who says?
The C++ Standard suggests it by what it *doesn't* require of
containers, and what it *does* require of allocators.
And what to use instead?


allocator<T>::size_type, IIRC.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Jul 22 '05 #5
Marc Schellens wrote:
can someone refresh my meory on what std::size_t is used for? I am wondering
if my template container class should have it's capacity as a size_t or an
int?
'size_t' ('std::size_t') is a type that can be used to hold a size of
any object in C/C++ program. Since an array in C/C++ is an object
itself, this type can also be used to store the size of an array. But in
generic case the concepts of "object size" and "container size" are
orthogonal and this type should not be used to store the size of a
container (number of elements).


Why?


It is rather obvious. Let me illustrate it by an example: when x86 was a
16 bit platform, certain C/C++ compilers used 16 bit unsigned integer
type as 'size_t'. That still didn't mean that numer of elements in
'std::list<>' was limited by 2^16. In that case the size of a single
elmement was limited by 2^16, but the maxumum length of the list was
only limited by the available memory.
And who says?
The important thing is that no one/nothing says that size of a container
should be limited by the range of 'size_t'.
And what to use instead?


Each container is allowed to have its own 'size_type'. If you are
designing a container, choose the appropriate type to represent is size.
If you are using a container, use its 'size_type' to hold the
container's size.

--
Best regards,
Andrey Tarasevich

Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: JKop | last post by:
I'm writing a ".cpp" and ".hpp" combination. The ".hpp" just contains one sole function declaration. The ".cpp" makes use of the function "std::strlen" and the type "std::size_t".
5
by: Joe Laughlin | last post by:
#include <iostream> int main() { std::string hello = "Hello World\n"; return 0; } This compiles fine. Is std::string defined in cstring? Or is it included
5
by: Pelle Beckman | last post by:
Hi, Honestly, what is this 'size_t'? And while I'm at it - what is a 'mutable' var.? I've understood it somehow makes a const a non-const, but what's the point of that? Short explanations?...
2
by: earthwormgaz | last post by:
I am trying to add the headers for a library I am using to a namespace to avert issues with name clashes. namespace Lib { #include <Lib/SomeFile.h> }; I am finding though that statements to...
5
by: greg.ruthenbeck | last post by:
Hi, I'm using Boost::uBLAS::mapped_matrix for working with sparse matrices. At the moment, the maximum dimension of mapped_matrix is 65535x65535 since std::size_t compiles as unsigned int...
7
Axon
by: Axon | last post by:
Is there a way to force std::size_t to be compiled as __uint64 (before STL etc are compiled). Where is size_t defined?
27
by: mike3 | last post by:
Hi. I can't believe I may have to use an array here. I've got this bignum package I was making in C++ for a fractal generator, and tried an approach that was suggested to me here a while...
4
by: Juha Nieminen | last post by:
Unknownmat wrote: VS2005 has a bug related to this. When you use size_t, it internally converts it to 'unsigned int'. In some situations it forgets that the type was actually size_t and only...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.