Welcome, Guest. Please login or register.

Author Topic: Best and fast way to AllocMem within an interrupt :Semaphores ?  (Read 7437 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Best and fast way to AllocMem within an interrupt :Semaphores ?
« Reply #14 from previous page: November 23, 2006, 08:38:08 PM »
They're all based on Allocate()/Deallocate(), so they're quite fast while memory is not fragmented.

However, FreePooled() is a bit special: It gets really slow due to the puddle scanning to find the proper memory header to call Deallocate() on. This gets exponentally slow.

AmigaOS 3.9 BB2 fixed this by using the new AVL tree binary balanced tree instead of simple linked list for the puddles.
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Best and fast way to AllocMem within an interrupt :Semaphores ?
« Reply #15 on: November 23, 2006, 08:40:07 PM »
Presumably then, they all have at least O(N) cost as a function of the number of nodes in the free memory list?
int p; // A
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Best and fast way to AllocMem within an interrupt :Semaphores ?
« Reply #16 on: November 23, 2006, 08:45:07 PM »
In the worst case every 8 bytes is allocated and free. This way it's the (memory_area_size / 8 / 2) nodes to walk thru before you find the correct chunk.

At Allocate(), if the large enough free memory chunk is after such alteration of allocated and free chunks, it needs to walk thru all of them to find the large enough one.

At Deallocate() it needs to walk all free chunks until it finds chunk to merge with (or to insert after).

Needless to say, fragmentation is bad. If you need absolute speed, I suggest using object cache for the time critical things, or other similar methods.
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Best and fast way to AllocMem within an interrupt :Semaphores ?
« Reply #17 on: November 23, 2006, 09:30:50 PM »
I'm interested in all of this as I weigh up the cost of writing my own custom allocator routines versus a basic wrapper for the memory pool allocation scheme.
int p; // A