e.g. ------------------------------------- | Code | ...... | Description ----------------------------------- | 0001 | ...... | John Woo | 0023 | ...... | Bruce Lee | 1012 | ...... | Jacky Chan I use the ITEM structure (or similar structures) to handle that ITEM STRUCT Code DWORD ? ; The code Desc DWORD ? ; The address of string of description Next DWORD ? ; The address of next ITEM structure ITEM ENDS The list is just simialar to the Go!Zilla one But i don't know how to handle the description string. Where to place the string in memory? The decription may be very long (may be up to 100kB or even more) and the list may also be very long ( may grow above 1000 ). Should I use file mapping or just memory allocation (but the list size is huge)? and how?
You must allocate memory dynamically. I use heap for such purpose.
I usually use GlobalAlloc, with the GMEM_MOVEABLE flag. This is for two reasons. 1.) It allows for almost any memory arrangement on a wide variety of motherboards all the way back to some old 486 laptops. 2.) I was told that on Windows NT (Not sure about 2k) Allocating fixed memory causes memory page thrashing and is better to use moveable memory and lock it when you want to access it. This also increases stability so long as you unlock and free the memory properly. I just finished implementing linked lists myself! If you'd like to see my code I could email it to you in about 1 week (Just finishing up school, pretty busy) You can edit the structure as much as you want so long as two items remain the same. NextNode (dword, ptr to next node in linked list) and PrevNode (Also dword, ptr to the previous node in list) So when I have a text field that I want in all of the nodes, when I create the node I also GlobalAlloc a text buffer filled with the "description" or whatever and place the handle/pointer in a dword in the nodes structure. Then when I delete the node I have to remember to also free the allocated string. This system works great but certain OS's (Like Win95) are limited to 16,000 and some off handles to memory, so your linked list is slightly limited. OF course any of the other newer versions of windows are only limited to the DWORD size (I belive) so you can have some odd 4 billion nodes. Email me if you want to see my code! See ya, Ben
I am confused with the memory functions since there are so many similar functions (HeapAlloc, GlobalAlloc, LocalAlloc, VirtualAlloc) and I don't know what's the difference between them... Which one should I use for the case?
Thanks all :)
I also have an interest in ASM linked lists. I know how to do it in C but don't know where to begin in ASM. Does anyone have any code they could send me? Or is there a tutorial somewhere on creating ASM linked lists? Icz??? Thanks
Frank, linked lists in asm will be identical to C 1) Work out how much space you will need per node! The easiest way to do this is a STRUCT NODE STRUCT dwData DWORD ? dwNext DWORD ? NODE ENDS 2) Have a stub: .DATA dwLLStart DWORD ? ;This is the pointer to the ; start of the linked list 3) Create a node, here you need to decide if you want moveable memory, or fixed... For more info on Fixed/Movable memory read the API docs on GlobalAlloc. If you choose moveable memory then the dwNext part of the LL will be a handle to memory instead of a definite pointer (I'll leave you to try that for yourself as its a little more complex). invoke GlobalAlloc, GPTR, SIZEOF NODE ;Allocate fixed mem "SIZEOF NODE" bytes long ;Read the docs GPTR, but it is fixed mem! ;Fixed mem returns the start of the allocated address in eax ;So..... mov dwLLStart, eax ;Have our stub pointing to the added space 4) Add a new node: ;edx is currently pointing to the last node in the list! push edx ;save it for later! invoke GlobalAlloc, GPTR, SIZEOF NODE pop edx mov (NODE PTR ).dwNext, eax ;Now the current node is pointing to the new node ;Same as current.next = new Node mov edx, eax ;current = current.next And after the fourth step the linked list was formed, and it was good ;) Mirno p.s. Remember to unalloc data again afterwards!
Thank you, I was kinda looking for a source code which performs a linked list. I don't have the ASM knowledge yet to do it by myself. I wanted to study a complete linked list so that I can gain the understanding and write one on my own. Or a tutorial on it would be even better as there would be an explaination of it and code. Thanks again
If anyone has source for a linked list code I really need it :)
I will write some tonight, and post it out to ppl who want it! I will try and tutorialise it as much as possible (but I'm still new to this whole asm malarky as well ;) Mirno
I've finished a simple linked list program! Its not big, and its not clever ;) I spent one night on it nuff said eh! But having said that, anyone who wants it post with e-mail address and I'll send it off! Mirno
me please.... firstname.lastname@example.org Thanks!
Hi I can use it, I'm interested in using it to make a quicksort routine. I'll just modify the work you have done to make a doubly-linked list. email@example.com Thank you!