Could one of the core devs shed some light on this issue?
I'm in the process of converting my softwaretitles from utilising a MemPool to something faster, for which actually 'malloc()' comes into view.
Especially when it comes to allocating many areas (like in HexView, where every line of the listbrowser is an allocation in the MemPool). Come to think of it, I may switch to 'ItemPool' for such occasions. My reason for switching is based on my insight gained from a test, as published here: https://os4coding.net/forum/some-curios ... ionmethods.
But why do I use a MemPool in the firstplace? Well, although I THINK I free all allocations properly, I may well have overlooked an occasion. A Mempool will provide me with the assurance that those allocations are freed explicitly at closing time. But as the test mentioned above has shown, using a MemPool is quite slow, up to a factor of 6 compared to 'malloc()'.
Now to be sure I have indeed freed up all allocated memory in the MemPool, I would like to traverse the Mempool and get a look at what allocations are not yet properly freed, before closing the program. The MemPool as allocated using 'AllocSysObject()' seems not to be using the 'struct MemHeader' & 'struct MemChunk' couple. When applying these two, the program crashes.
The function used for this analysis:
Code: Select all
#ifdef DEBUG
void Check_MemPool(APTR MemPool)
{
INFO_ENTER
struct MemHeader *MH;
struct MemChunk *MC;
_GetFirstNode(MH, MemPool);
while (MH != NULL)
{
_PrintFlags(MH->mh_Attributes);
/*
** Funny info provided:
*/
_Info("Lower . . . . .: [ %08lx ]", MH->mh_Lower);
_Info("Upper . . . . .: [ %08lx ]", MH->mh_Upper);
_Info("Free . . . . .: [ %8ld ]" , MH->mh_Free);
MC = MH->mh_First;
while (MC != NULL)
{
/* This makes the system crash! */
// _Info("Size . . . . .: [ %8ld ]", MC->mc_Bytes);
MC = MC->mc_Next;
}
_GetNextNode(MH);
}
INFO_VACATE
}
#endif
Code: Select all
#define _GetFirstNode(L, N) (N=(typeof(N))IExec->GetHead((struct List *)L))
#define _GetNextNode(N) (N=(typeof(N))IExec->GetSucc((struct Node *)N))
# define _PrintFlags(Flags) do{uint16 FC=(sizeof(Flags)*11)-1, S=(sizeof(Flags)<<3);typeof(Flags)R=1;uint8 FA[FC];memset(FA,0x20,FC);\
FA[--FC]=0;while(R){FA[--FC]=48+((Flags&R)!=0);FC-=((--S%4)==0);FC-=((S%8)==0);R<<=1;}\
PRINTF("FLAGS: * %-28.28s [ %s ]\n", #Flags, FA);}while(0)
# define _Info(Fmt, Args...) PRINTF("INFO : "Fmt"\n", ##Args);
#ifdef USE_SASHIMI
# define PRINTF IExec->DebugPrintF
#else
# define PRINTF IDOS->Printf
#endif