home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / mswindo / programm / misc / 5290 < prev    next >
Encoding:
Text File  |  1993-01-23  |  2.1 KB  |  45 lines

  1. Newsgroups: comp.os.ms-windows.programmer.misc
  2. Path: sparky!uunet!microsoft!wingnut!tonplooi
  3. From: tonplooi@microsoft.com (Ton Plooy)
  4. Subject: Re: Global memory question
  5. Message-ID: <1993Jan22.115122.17446@microsoft.com>
  6. Date: 22 Jan 93 11:51:22 GMT
  7. Organization: Microsoft Corporation
  8. References: <1993Jan21.043651.22090@empire.cce.cornell.edu>
  9. Lines: 34
  10.  
  11. In article <1993Jan21.043651.22090@empire.cce.cornell.edu> avinogra@empire.cce.cornell.edu (Alex Vinogradov) writes:
  12. >Hello,
  13. >I have to allocate large number of small memory blocks (for simlicity, let's
  14. >say that it is a huge linked list each node of which is quite small).  The
  15. >problem is in following -- I cannot use local memory for it since it gets
  16. >overflowed pretty fast; the problem with global memory is that I do not
  17. >want to spend 20 bytes for overhead for each of my 20-30 bytes memory blocks
  18. >because I will be using nearly twice as much memory as I really need.  Does
  19. >anyone has any ideas on how should I design my memory management scheme?
  20. >I don't think I am the first one who came up with this question, but none
  21. >of the books in local library mentions that.
  22. >
  23. >The other related to this question I have: what is GetSelectorBas() / 
  24. >SetSelectorBase()?  I did look it up in Microsoft manuals but they ain't
  25. >too informative on this issue.
  26. >
  27.  
  28. If you have the MS C7 windows libraries, the _fmalloc function implements
  29. it's own subsegment allocation scheme under windows. It's in my opinion much
  30. better to use this function than the GlobalAlloc/GlobalLock functions. If 
  31. you want to implement your own memory allocation functions, you could try 
  32. out the following. Use GlobalAlloc to allocate a block of data, switch DS 
  33. to the DS of this block, call LocalInit(DS, 0, size) and restore DS. On 
  34. subsequent allocations use LocalAlloc on this block (swapping DS). I remember 
  35. reading an article by Andrew Schulman who implemented this, but I'm not sure 
  36. I have al the details right.
  37. The Get/SetSelectorBase functions are used for accessing specific memory 
  38. addresses, GetSelectorBase retrieves a linear address (divide this by 16 
  39. to get a segment address).
  40.  
  41. Bye,
  42.  
  43.     Ton
  44.  
  45.