Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Once you allocate memory for a node (using malloc) you should be able to do sizeof(yourDataType). So to get the total size of the linked list you traverse the list and get the count of nodes:</p> <pre><code>Total Size Of Linked List = SizeOf(One Node) * Count Of Nodes </code></pre> <p>For instance:</p> <pre><code>int getCountOfList() { Node* temp = head; //assign a temp node to the head of the list int count=0; while(temp) { count++; temp = temp-&gt;next; //move to next node } return count; } </code></pre> <p>Then you take that count and multiply by size:</p> <p>size = getCountOfList * sizeof(mydatatype);</p> <p><strong>This will give you the size of the actual linked list but becareful as the linked list node has pointer elements which in and of themselves can allocate memory as well. This will need to be accounted for...</strong></p> <p>For instance, one of those char* elements within the node could malloc some more space and use up some memory.</p> <p>If you actually need the entire size of the list including allocated elements for all other char* pointers for example, you simply:</p> <p>1)Traverse the list and look into each node</p> <p>2)For each node you check if the elements of each node point to any other allocation (for instance char* data may allocate 50 characters to store). If it isn't null you get the length of the string + 1 (for terminating char) and you multiply that by sizeof(char) (for this example)</p> <p>3)You do that for each node and store that size, then move to next node</p> <p>4)You take the SUM of all of these char* (in this case) for each node and accumulate for the entire list.</p> <p>5)Once you have that simply add this sum that will give you the size of all nodes.</p> <p>Then total size becomes:</p> <pre><code>SizeOfAllNode + (SizeOf(dataType) * CountOfNodes) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload