| 05-21-2007, 11:26 PM | #1 |
Hi, I whipped up this sample test map that allows you to implement a malloc and free in your own map. Why would you use this over gamecache? I haven't a clue. It's probably faster. BUt by how much I couldn't say, oh and it uses gamecache to store sizes of things stored in memory. Since the atomic unit size in jass is 4bytes malloc(1) retrieves 4 bytes by returning an integer. Simmilarly malloc(4) returns 16 bytes by referring to the first point where 16 free ints could lie. It's usage is pretty simple: JASS:int malloc(int size) Finds size amount of blocks free in memory and returns a ptr or returns -1 if you don't have a chunk large enough. void free(int ptr) Frees a ptr and all associated memory. It is an error to call free on a non-malloced ptr. int mget(int ptr) Gets the value located at memory location ptr void mset(int ptr,int value) Sets memory location ptr to value void test(int exit) prints all memory locations up to exit There is a simple test included with the map. You can press escape to make malloc(5) 3 times, then free the second pointer, then malloc(6). You can then type 24 to see the first 24 location. It's a simple test but it shows that malloc doesn't waste memory. This actually is probably best with an automated script that would take some keywords like struct and do the malloc and then actually be able to use the benefits of this over the crappier gc performance. |
| 05-22-2007, 03:54 AM | #2 |
Hey Weaaddar, we researched this stuff soon after you left. Check out: http://www.wc3campaigns.net/showthread.php?t=87358 |
| 05-22-2007, 06:03 AM | #3 |
yeah, i see that now. I'm really interested in Vex's vJass but the annonyance of static size is a major bog down. I'm trying to create a malloc library that can up to N arrays where N is something you give to a text macro. But I'm having a lot of difficulty learning the new syntax and playing with these toys. It's awesome how jass has been mutated, but its also terrible that we still have to stick to the awful syntactic salt. I wish the scripts would have gotten rid of things like set and call and would've replaced then with { and end if with } etc. The fact that I have C style power, but with the pain of jass is well unfair. |
| 05-22-2007, 06:52 AM | #4 |
It doesn't really make sense to get rid of set because '=' isn't an operator. Getting rid of call you could argue for but what's the point to writing expressions that aren't in a set? Call indicates that whatever is next isn't an expression. It would be nice to eliminate statements and have a purely expression based language. The VM is flexible enough for this, but the compiler isn't... This is my own opinion on what is logical. You can throw together a translator pretty quickly for your own tastes; We have parsers for vanilla JASS in haskell and ocaml if you want to get involved. Personally, I would like the option of indentation delimited blocks. |
| 05-22-2007, 07:10 AM | #5 |
well, why can't = be an operator? Things like local are also superflous. I haven't written things in haskell and ocaml since like last year all i've played with is C and C is distrubingly grand. |
| 05-22-2007, 07:57 AM | #6 |
Well you can compile something like v1 = v2 = e1 trivially to set v2 = e1 ; set v1 = v2 That would be pretty nice for nulling- v1 = v2 = v3 = v4 = null -as long as you have a constant propagation optimization. But if you really want it to be expressions you need to figure out the meaning of things like (v1 = v2 + (v2 = e1) + v2). That seems pretty hopeless to me, so I would leave it at just chains of lvalue = expr, but then you've still got just a statement, so leaving the set keyword makes sense. As long as you indent properly Jass's keywords enforce a neat, readable style which is pretty important for pasting code around in this forum. I'm with you on local though, what with the precedent already there for globals. |
| 05-22-2007, 02:54 PM | #7 | |
We all hate the verbosity, but like I said already vJass being an extension to Jass I cannot just remove them. We are planning to make a whole new language once we get the time, that would be july or something like that. Regarding structs, I am afraid I traded a lot of things for speed, but, the initial plan was to use my dynamic arrays which are indeed identical to your malloc/free. What made me step back is that you need the extra calls and it eventually turns out that it gets more size limitations in practice than using what I do know with structs. Each type gets its onw 8190 instances limit, instead with the other things there is a total index limit of a multiple of 8190 If you ask grim001 and toadcop my plans to get rid of the 8190 limit exist. We figured out that the best way would be to use some kind of static binary search. Each declaration of struct would allow to set an instances limit, in case it is bigger than what we could get with 8190 it will use multiple arrays and then a function will either do linear search with if then else or if the total arrays number is bigger than 10 we will use a binary search. In some post I even had prepared the base of that binary search. I think toadcop fell in love with it so I would not be surprised if he already made something like TCBuffer using it already. Of course, implementing it will be really painful, so I am waiting till I get more time or get to replace my compiler with something more decent and get rid of pascal. Quote:
Code:
if (a=true)
{
//do something
}This is the infamous issue with = as operator, the coder will make that mistake and the compiler will not get aware until the random bugs appear in runtime. Not to mention that compiling it to Jass is going to be pretty messy. We could just allow it for set x=g=b=null (or without set for the next language) in fact, I think I am gonna add that to vJass asap since it is something I really miss sometimes. Code:
Personally, I would like the option of indentation delimited blocks. -- Don't worry though, we could all make our own languages with the things we like. We gave up on standards plenty of time ago. |
| 05-22-2007, 08:35 PM | #8 |
hows about semi-colons? They make me feel all warm and fuzzy. White space delimitation seems wrong after spending so long with C. |
| 05-24-2007, 12:59 AM | #9 |
Hmm the preproccessor with WEHelper isn't very strong. Theres no way for me to automate the amount of arrays generated and the appropriate changes to mset and mget. I updated my malloc, its now a library! The initialization was greatly optimized in that there is no initialization. Whenever malloc is called, it first checks the free list. If the freelist cannot find a chunk of suitable length it expands the heap. If expanding the heap would go past all usable memory, malloc fails. Free returns an unused block to the the free list and/or shrinks the heap if neccessary, free only fails on null pointers. A new struct was added for pointers. Malloc now returns a pointer, and free now takes a pointer. Malloc returns a pointer if it succeeds, 0 if it fails. free takes a pointer returns true if freeing work, false if it fails. mget and mset are private functions. The test map was updated with an example usage of the pointer type. I added an IV struct which is a very simple item vector with a fixed capacity. There is an item called an Item Printer, you can put items in it by drag and drop, and access it by clicking the item. You can alternatively still type in any number to get a raw print of memory. The link at the top has been updated with the new version. |
