Welcome, Guest. Please login or register.

Author Topic: NewList() - Do we need to allocate memory?  (Read 3299 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline nyteschaydeTopic starter

  • VIP / Donor - Lifetime Member
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 643
    • Show all replies
    • http://www.nyteshade.com
NewList() - Do we need to allocate memory?
« on: January 10, 2017, 02:23:22 AM »
When using the NewList() function described in exec/lists.h (at least in SAS/C 6.58), does one need to allocate memory for a new list separately? What does NewList() do exactly?

Code: [Select]

/* Is NewList(struct List *) the same as the following? */
struct List *list;

list = (struct List *)AllocMem(sizeof(struct List), MEMF_ANY);
memset(list, 0L, sizeof(struct List));

/* Or does it do some magic black box stuff? And if I want to pass
    my list around, should I malloc() the memory for the list and then
    remember to free it myself later; after passing it around */
list = (struct List *)malloc(sizeof(struct List));
NewList(list);
// ... use the list
free(list);
Senior MTS Software Engineer with PayPal
Amigas: A1200T 060/603e PPC • A1200T 060 • A4000D 040 • A3000 (x2) • A2000 Vamp/V2 • A1200 (x4) • A1000 (x3) • A600 Vamp/V1 • A500
 

Offline nyteschaydeTopic starter

  • VIP / Donor - Lifetime Member
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 643
    • Show all replies
    • http://www.nyteshade.com
Re: NewList() - Do we need to allocate memory?
« Reply #1 on: January 10, 2017, 02:34:11 AM »
Also, do the Amiga link list style methods include one that counts or one that counts the number of items in the list? Is there a method that will walk the link list until next points to null or next points to the head and count or should we have to write that ourselves?
Senior MTS Software Engineer with PayPal
Amigas: A1200T 060/603e PPC • A1200T 060 • A4000D 040 • A3000 (x2) • A2000 Vamp/V2 • A1200 (x4) • A1000 (x3) • A600 Vamp/V1 • A500
 

Offline nyteschaydeTopic starter

  • VIP / Donor - Lifetime Member
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 643
    • Show all replies
    • http://www.nyteshade.com
Re: NewList() - Do we need to allocate memory?
« Reply #2 on: January 10, 2017, 09:38:46 PM »
As usual, you are a fantastic teacher. You hold so much in the way of domain knowledge. Thanks for taking the time and teaching. I may have more questions along different topic lines. I'll post in new threads so others can benefit from my learning and your teaching.

<3
Senior MTS Software Engineer with PayPal
Amigas: A1200T 060/603e PPC • A1200T 060 • A4000D 040 • A3000 (x2) • A2000 Vamp/V2 • A1200 (x4) • A1000 (x3) • A600 Vamp/V1 • A500