Posts: 15,941
Threads: 0
Joined: Jun 2008
OK, I didn't mention that I'm not allocating small blocks from the heap - I just allocate one huge (several Mb) block once, then allocate from within there. I don't have benchmarks; I can get some but I'm not sure what you want benchmarking - the "malloc" function? Because of the way the code works, actually using the allocated memory is just the same as a standard array access and an addition.
As for fragmentation, that is an issue I've not been able to deal with because I'm currently using direct pointers rather than indirect ones. I could change model and then I could do compression and just update the indirection array, but obviously then you have more code involved (I could make it an option I suppose). The allocation algorithm is the most basic one too - it just allocates from the first free block of sufficient size, there is also "smallest" and "largest", which allocate from the closest matching or most free blocks - it would be interesting to see how they affect fragmentation. "free" is clever though and can merge adjacent blocks when they are both free to give a larger block from which to allocate.
Posts: 15,941
Threads: 0
Joined: Jun 2008
18.04.2013, 14:49
(
Последний раз редактировалось Y_Less; 18.04.2013 в 19:09.
)
Quote:
Originally Posted by Slice
Very crafty. Nice!
I'd suggest you make it so each library could tell y_malloc how much memory it wants, then it'd be added up and "stolen" on startup.
That way each library could worry about its own, and get all the memory it wants.
pawn Код:
#define MALLOC_SPACE_WANTED 10485760 #include <ysi\y_malloc> #define MALLOC_SPACE_WANTED (MAX_SOMETHING * 1024) #include <ysi\y_malloc>
|
I'm not sure that's possible when using "#pragma dynamic".
Quote:
Originally Posted by Dan..
Benchmarks with the older version of `malloc`. Anyway, I think this is one is a little slower than the older one.
Can people allocate more memory than those "several Mb"?
|
No, but you can tell it to allocate more initially.
Edit: It turns out I missed something very important. Once I was done with the code I removed all the debug prints and it instantly stopped working! I'm still not 100% sure of the issue, but I think it might be this in amx.c:
pawn Код:
case OP_SYSREQ:
GETPARAM(offs);
/* save a few registers */
amx->cip=(cell)((unsigned char *)cip-amx->code);
amx->hea=hea;
amx->frm=frm;
amx->stk=stk;
Pretty sure that saves something important for my code, and once I removed "print" I removed the call to it.
Posts: 15,941
Threads: 0
Joined: Jun 2008
Today I learned why this problem exists:
Quote:
Originally Posted by Y_Less
Edit: It turns out I missed something very important. Once I was done with the code I removed all the debug prints and it instantly stopped working! I'm still not 100% sure of the issue, but I think it might be this in amx.c:
pawn Код:
case OP_SYSREQ: GETPARAM(offs); /* save a few registers */ amx->cip=(cell)((unsigned char *)cip-amx->code); amx->hea=hea; amx->frm=frm; amx->stk=stk;
Pretty sure that saves something important for my code, and once I removed "print" I removed the call to it.
|
I was basing all my code on the source code for the 3.2.3664 build of PAWN as that's what the compiler reports. However, I had a brainwave and remembered that I had upgraded the compiler independently from the VM when I was a dev, so I got the 3.0.3367 source code and discovered that it was missing these two important lines from the "op_halt" code:
pawn Код:
amx->frm=frm;
amx->stk=stk;
Which entirely explains why it broke when I didn't call "SYSREQ" first.
Posts: 15,941
Threads: 0
Joined: Jun 2008
"," and ";" mean different things - make sure you read the documentation on what the differences actually are or your code may not do what you think.
Posts: 15,941
Threads: 0
Joined: Jun 2008
Err - no you didn't!
pawn Код:
for (new i = 10; i != 0; --i)
Or as most people would write it:
pawn Код:
for (new i = 10; i >= 0; i--)
Note that you have to be MUCH more careful with OBOEs (Off By One Errors) with downwards loops - that code above will run 11 times, including for index 10, which will cause errors if any arrays re of size 10. An alternate way that avoids this issue is:
pawn Код:
for (new i = 10; --i != 0; )
pawn Код:
for (new i = 10; --i >= 0; )
pawn Код:
for (new i = 10; i-- > 0; )
Those are all equivalent, and will run from 9 to 0 (inclusive).
Posts: 15,941
Threads: 0
Joined: Jun 2008
Your way doesn't even work - it counts up from -10 to 0.
Posts: 2,938
Threads: 162
Joined: May 2010
Today I learnt how to deal with OBOEs thanks to Y_Less.
Quote:
Originally Posted by Y_Less
Note that you have to be MUCH more careful with OBOEs (Off By One Errors) with downwards loops - that code above will run 11 times, including for index 10, which will cause errors if any arrays re of size 10. An alternate way that avoids this issue is:
pawn Код:
for (new i = 10; --i != 0; )
pawn Код:
for (new i = 10; --i >= 0; )
pawn Код:
for (new i = 10; i-- > 0; )
Those are all equivalent, and will run from 9 to 0 (inclusive).
|
Awesome, I like this.
Today I really learnt some stuff about queue's (not really pawn related)
http://en.wikipedia.org/wiki/Queue_management_system
http://en.wikipedia.org/wiki/Queueing_theory
http://en.wikipedia.org/wiki/Queueing_delay
http://en.wikibooks.org/wiki/A-level...oncepts/Queues
I don't think this is what I really wanted though.
I couldn't really find much other sites other than wikipedia.. hopefully someone can link me.
Posts: 15,941
Threads: 0
Joined: Jun 2008
Posts: 544
Threads: 45
Joined: Mar 2012
Reputation:
0
Today I learned how to use the '%' operator!