capacity

Pages: 12
hi. what is the capacity in terms of a string of the data part of one node in a linked list?
Last edited on
if you're asking about the capacity of a string, http://www.cplusplus.com/reference/string/string/capacity/

in essence, there is no hard limit other than your hardware
There is a limit, it is usually the maximum value of whatever type is returned by capacity.

size_t max_size ( ) const;

In this case size_t.

Which is a typedef for unsigned int.

Which for a 4byte unsigned int is
4294967295
Last edited on
actually my question is, for example:
Node *loc = new Node;
(*loc).data = 10;
Tail = loc;
(Tail).next = Tail;
in the line above: (*loc).data = 10;
can I let data = whoWasLastToPlay?
size_t = unsigned int, if int is 4 bytes (32-bit platform) then the max size of size_t is around 4.2 billion, but like I said, the limit is your hardware.
It isn't the hardware limiting if you have more than 4gigs of memory and 64bit system. If you have say 12gigs like I do, then you can only store size_t char's in a string.
Last edited on
64-bit unsigned integers can hold an unsigned int of 32-bit*32-bit, or 4.2 billion times 4.2 billion

Also, some hardware doesn't support 64-bit operating systems, or 32-bit operating systems, etc

so like I said, the limit is your hardware, note that strings store chars, which are 1 byte, so 12 gigabytes means up to 12 billion chars before you run out of memory, I'm not sure if strings use linked lists or vectors but there is also a memory overhead from that to account for.

Node *loc = new Node;
(*loc).data = 10;
Tail = loc;
(Tail).next = Tail;
in the line above: (*loc).data = 10;
can I let data = whoWasLastToPlay?


if whoWasLastToPlay is an int, yes (in that specific scenario, because 10 is an int)
Last edited on
to clarify: a node in a linked list contains a data part, and a pointer to the next node. Again, for example, in the line above (*loc).data = 10; data refers specifically to the contents (10 in this case) of the data part of that one node. My question is other than the number 10, as is the above instance, can the"data" part of a node hold a string, and if so, is there a limit to the size of "that" string.
We are talking about std::string yes? Did you even read the link you posted?

The real limit on the size a string object can reach is returned by member max_size.

I am talking about an std::string. A std::string as standard uses an unsigned int. It cannot store more than the max of an unsigned int.

If you write your own string class or use another string class that uses another data type for storing information such as size/capacity then the limit will be the data type. As for run time if you have less bytes than the data type, the limit will be hardware.

There are two different times of limits. There is how much the string class can hold due software limitations. And there is how much memory you have to work with at runtime.

Last edited on
a node can hold a string as its data if that's the data variables type, yes.

I did read the link I posted, and the limit is an unsigned int amount of characters, e.g 4.2 billion characters, agreed so far?

unsigned int on 32 bit may be 4.2 billion characters, but it is 4.2 billion times that on 64-bit, and x-bit/32-bit/64-bit is dependent on both hardware, your operating system, and your compiler.

so for a 64-bit implementation, the limit is some huge number I don't even know the name of, but that is excluding the memory you have available, that is more likely to be the limit on a 64-bit implementation than a 32-bit implementation, for now anyway.
Last edited on
Incorrect. An unsigned int is 4 bytes in 32 or 64 bit OS. If you want a 64bit int you have to use a long int. Because string uses a unsigned int it will have the limit as such.

Pointers on the other hand DO change size depending on 32 or 64 bit operating system.
You're right, ints in C++ are either 16-bit or 32-bit, they can't be 64-bit.
Last edited on
ROFL, who said anything about a 64bit int? I mean other than you.
Last edited on
I am trying to make a long question short, but I will expand for the sake of sanity. I implemented the following as a static array:
void CircleList::add(string s)
{
Player p;
p.name=s;
if(count==0) // no players at the table
{
// special case: adds a player to an empty table
playerArray[0]=p;
count=1; // adds the first player
whoWasLastToPlay=0; // whoWasLastToPlay at pos 0
}
else
{
for(int i=count-1; i>=whoWasLastToPlay+1; i--)
{
playerArray[i+1]=playerArray[i];
}
playerArray[whoWasLastToPlay+1]=p;
count++;
}
}

CircleList is a class. The above adds a player to a table game(game is not important). Now I am trying to implement the same add funtion with a dynamic, pointer based linked list. Hence, my empty headed questions above.
Sorry, what was the question in the post above?
Last edited on
its a two part question: first, what do I do to have the code display correctly with the proper spacing and indentations; second, I am trying to implement the same code as a dynamic, pointer based singly linked list. thank you for your responses.
EddieV223 wrote:
An unsigned int is 4 bytes in 32 or 64 bit OS.

It doesn't have to be. It depends on the compiler.

EddieV223 wrote:
Because string uses a unsigned int it will have the limit as such.

size_t doesn't have to be a typedef for unsigned int. On 64 bit compilers it's often a 64 bit integer. Note that even if sizeof(size_t) == sizeof(unsigned int), it doesn't mean they are necessary the same type.

Zephilinox wrote:
You're right, ints in C++ are either 16-bit or 32-bit, they can't be 64-bit.

Sarcasm?

Last edited on
1. I answered that in the other thread.
2. so when you call add, you want it to make a node and then link that node with the last node in a linked list? and it still isn't a question, what exactly do you need help with? do you have any code for it already? do you not know what to do or where to start? do you have a single linked list?
Last edited on
I put the code in code tags. It still does not display correctly. What I'm I doing wrong!!!???
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void CircleList::add(string s)
         {
             Player p;
             p.name=s;
             if(count==0) // no players at the table
             {
                 // special case: adds a player to an empty table
                 playerArray[0]=p; 
                 count=1; // adds the first player
                 whoWasLastToPlay=0; // whoWasLastToPlay at pos 0
             }
             else
             {
                  for(int i=count-1; i>=whoWasLastToPlay+1; i--)
                  {
                       playerArray[i+1]=playerArray[i];
                   }
                   playerArray[whoWasLastToPlay+1]=p;
                   count++;
             }
         }
Last edited on
code tags doesn't mean brackets around your code. it means brackets around the word "code" before your code, and then after your code brackets around the word "/code"

e.g [code]int main(){}[/ code]

(the reason that didn't turn into code is the space after '/'

edit: or you can do it the easy way, simply highlight your code when it is in this reply box, and click the "<>" button on the right-hand side, next to the bold, italic, underline, etc buttons.
Last edited on
Pages: 12