Welcome, Guest. Please login or register.

Author Topic: AllocMem/AllocAbs/FreeMem()  (Read 4093 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
AllocMem/AllocAbs/FreeMem()
« on: January 11, 2017, 12:27:16 AM »
So looking at the AllocMem/AllocAbs/FreeMem methods in Amiga exec, I noticed that it requires you to keep track of how much memory to free when the time comes to do so. What are the most common ways that you do this? Do you use an exec List to track it? A global variable?

It seems the advantage is that AllocMem takes a request on which type of RAM you are asking to allocate from (CHIP, FAST, 32BIT, etc...). What is the difference in using the exec memory functions over the standard C ones like malloc/calloc/realloc and so on?

Additionally, using the Amiga paradigm, if I wanted to implement a ReAllocMem() function, I presume a few things would have to be done in order do this.

1. Try using AllocAbs() to get the additional memory immediately after the memory allocated with AllocMem().
2. If unavailable, do an AllocMem() for the total size desired and copy the memory from the original location to the new one. Finally, freeing the old one.
3. Return NULL if there was no chance to allocate the full new block in step 2.

Should I go through all this trouble? Why should I use the exec memory functions over the C memory functions? Are there any performance benefits to doing so? What about any other unintended side effects of not using the Amiga Exec routines?
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