ListBrowser AllocListBrowserNode LBNCA_CopyText

3 posts / 0 new
Last post
JosDuchIt's picture
Last seen: 6 years 1 week ago
Joined: 2012-01-08 20:57
ListBrowser AllocListBrowserNode LBNCA_CopyText
  1. listbrowser.gadget/SetListBrowserNodeAttrsA
  2. listbrowser.gadget/SetListBrowserNodeAttrsAer.gadget/SetListBrowserNodeAttrsA
  3. LBNCA_CopyText (BOOL)
  4. Specifies that you want the LBNCA_Text copied to an internal
  5. buffer by ListBrowser. This tag must precede LBNCA_Text in
  6. the tag list. For example,
  7. ...
  8. LBNA_Column, 2,
  9. LBNCA_CopyText, TRUE,
  10. LBNCA_Text, "Amiga", // Text will be copied
What is the advantage of usingt this TAG when creating a node list node = IListBrowser-> AllocListBrowserNode(1, LBNCA_CopyText, TRUE, LBNCA_Text,Buffer, TAG_DONE); over just node = IListBrowser-> AllocListBrowserNode(1, LBNCA_Text,Buffer, TAG_DONE); ???
hypex's picture
Last seen: 1 month 3 weeks ago
Joined: 2011-09-09 16:20
The obvious thing to my mind
The obvious thing to my mind is that you don't need to keep your strings in memory and can free up the memory used. Of course if your strings are inside your code as normal constant char pointers then it has no main advantage. However, say you load your labels from disk (perhaps in different languages), or generate them on the fly from a directory scan, then the string can be copied and the memory used for those labels freed or reused by the code. :-)
thomas's picture
Last seen: 3 days 4 hours ago
Joined: 2011-05-16 14:23
If your buffer stays valid
If your buffer stays valid while the node lives, there is no advantage, it's rather a waste of memory. But if your buffer is volatile, you cannot live without copying it into permanent memory. Example:
  1. struct Node *new_node (const char *name,long size)
  3. {
  4. char buffer[20];
  5. struct Node *node;
  7. sprintf (buffer,"%ld",size);
  9. node = AllocListBrowserNode (2,
  10. LBNA_Column,0,
  11. LBNCA_CopyText,FALSE,
  12. LBNCA_Text,name,
  13. LBNA_Column,1,
  14. LBNCA_CopyText,TRUE,
  15. LBNCA_Text,buffer,
  16. TAG_END);
  18. return (node);
  19. }
Log in or register to post comments