What does GlobalLock reaaly do ?

Hi all,

I am not sure if this is the most appropriate place for this function, but I could not think of anywhere esle.

In MSDN, it says that this function exists for backwords compitability.
But stil it says that it does “Lock”, it just does not say what does it “Lock”.
What does it really do ?

Thanks
Maurice

It is user mode windows platform stuff. So this would be the wrong
forum. Google provides a wealth of information on the topic. For
example:
http://blogs.msdn.com/oldnewthing/archive/2004/11/04/252258.aspx

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@netvision.net.il
Sent: Thursday, February 08, 2007 5:39 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] What does GlobalLock reaaly do ?

Hi all,

I am not sure if this is the most appropriate place for this function,
but I could not think of anywhere esle.

In MSDN, it says that this function exists for backwords compitability.
But stil it says that it does “Lock”, it just does not say what does it
“Lock”.
What does it really do ?

Thanks
Maurice


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Hmmm… This is an entirely user-mode question, but here goes the answer: It REALLY does exactly what it says in MSDN:

http://msdn2.microsoft.com/en-us/library/aa366584.aspx

Seriosuly. It doesn’t turn into a native system service or anything, if that’s what you’re asking.

Check out the “history” of this call:

http://blogs.msdn.com/oldnewthing/archive/2004/11/04/252258.aspx

Just so you know: Google can be a wonderful thing.

Peter
OSR

GlobalLock was part of the Win16 memory manager. These days, it’s basically irrelevant. I think the idea was that you could allocate moveable memory, and the heap manager would shuffle memory around (compact it).

Obviously, apps get rather surprised when memory they are using suddenly moves elsewhere, so you could use GlobalLock to “pin” memory in place, use it, then call GlobalUnlock to return access to it to the heap manager.

I’m not sure if it worked back then or not, or if it did, if it provided much benefit, or if it did provide any benefit, if people used it. But these days, Win32 is a flat memory model, and at least for unmanaged apps (non-GC), the heap manager always allocates fixed blocks. I can’t say I trust 99% apps to handle memory correctly even with stable addresses for heap blocks, much less when the heap manager can shuffle them around. (GC! GC! GC!)

The docs on GlobalLock and GlobalAlloc explain this, although perhaps not completely, and without much historical scope.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@netvision.net.il
Sent: Thursday, February 08, 2007 2:39 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] What does GlobalLock reaaly do ?

Hi all,

I am not sure if this is the most appropriate place for this function, but I could not think of anywhere esle.

In MSDN, it says that this function exists for backwords compitability.
But stil it says that it does “Lock”, it just does not say what does it “Lock”.
What does it really do ?

Thanks
Maurice


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Arlie Davis wrote:

I’m not sure if it worked back then or not, or if it did, if it
provided much benefit, or if it did provide any benefit, if people
used it.

It did work back then, and it was immensely useful. Back in the day,
when a top-of-the-line 20MHz 386 had a meg or two a RAM (NOT a typo :-),
if you had to work with lots of memory, that was the only way to do it.

I was writing code which worked with scanned documents; usually 8.5x11
inch 300 DPI images, which had to be decompressed, scaled, and displayed.

The only was to do in then was to break the image up into 64KB chunks of
movable memory, and just lock down the one you were currently working with.

Ah, those were the days (and my beard is grayer for it)!

Cheers,

– mkj


//
// Michael K. Jones
// Stone Hill Consulting, LLC
// http://www.stonehill.com
//_______________________________________________

Now I DO feel old! I remember using Windows 2.01 (my initial contact with it), where one attraction of Global… was that it enabled you to have a common API for using bank-switched memory (which on 8086 and 80186 processors was the only way you could have more than 1MB), EMS, and probably a few other extension mechanisms I’ve thankfully forgotten. Even the wonderful SDK documentation where GetProfileString and WriteProfileString had identical descriptions [except for the API name].

Which then reminds me of my first PC- bought with the IBM employee discount [they had to randomly assign delivery dates because the demand was so high- I was several months out, but it could have been a much longer wait than that], I’d loaded it up with 2 320K 5.25" floppies, 256KB of RAM, monochrome display and the IBM (really Epson) dot matrix printer- filled all the slots. For software, I added IBM DOS 1.0, UCSD p-System PASCAL, IBM MASM 1.0, IBM PASCAL 1.0, and Microsoft Adventure, which I bought because I’d played the original Adventure on the early internet shortly after I graduated from college and had just barely figured out getting past the dragon- all the IBM products of course being from Microsoft too, although I don’t believe I knew or cared at the time. Rounded out with the DOS and hardware tech references, including the indispensable listing of the entire BIOS, I was already at $5K, even with the discount. I’d cringe if I inflation adjusted that number. AS it was, if I hadn’t been single and frugal, I couldn’t have afforded it.

Wrote PASCAL programs with EDLIN, compiled them with three or four diskette swaps (2 or 3 compiler passes [can’t remember] and then the linker), and debugged them with DEBUG (odd little debugger with a bunch of quirky one and two letter commands- or is that the one I used this morning?). No source code debugging, just linker maps and combined source/assembler output from the compiler if you had to go there… Assembler was a bit easier, just two diskette swaps, and I really enjoyed working with it, particularly since with the tech refs and a little inspired hacking I could program everything in the box down to the metal.

It was heaven, because I could write any kind of program I wanted, and not worry about my efficient usage of $1000/hr mainframe time [connect time charges from an interactive terminal were mercifully smaller, but they also added up]. One infinite loop while you were off getting coffee could set your career back markedly in those days. I wrote a virtual memory manager, a couple of heap managers, a merged multi-display [character “graphics”] windowing package, a keyboard driver or two, a digital circuit simulator, a Z80 emulator, and I don’t know how much else- none of which I could sell, of course, and by today’s standards much of it was probably trash, but they worked well enough and at least I understood something about that kind of software when I was done.

It was a magical time- my own private world where I could create what I wished when I wished, do it the way I wanted, and nobody could force me to adopt something I didn’t think fit the mental model I was working to.

Of course, it didn’t last long- my favorite retirement fantasy is usually getting or building a system. I still remember a few of my ancient design and prototype manufacturing skills, although I was never terribly good with a soldering iron or wirewrap tool. Heck, maybe even go back and start with the instruction set and design the whole CPU logic and try my hands at something like an FPGA again [did that once, but of course never could afford to implement or debug it, even in SSI / MSI]. Then start creating the whole software set up from the bare metal- maybe put together some simple BIOS with basic drivers for the storage and I/O devices I’d have to have, then write an assembler in hex [yep, I actually tried to do that at an even earlier time with some Motorola development system I’d managed to get second hand- lost all the “source” eventually when I either accidentally last track of which Dolby NR setting was on the cassette recorder I was using for storage, or left the cassette too close to a bulk eraser- I remember both being problems], then a basic operating system, or some trivial apps, then something a little better. Of course I’d never be able to finish it, and I would probably never have anything generally useful to anyone else [what interoperability?], but that would be missing the point [no customer, no schedules, no deadlines, no IP issues, no commitments, just me and my keyboard, free to do as we wish for whatever time remained to me]…

On the other hand, #2 is playing Halo about 100 hours a week, for however long it takes someone with my age-affected reflexes, visual acuity and reaction times to actually survive Legendary without dying a bazillion times.

Anyway- those were indeed the days- thanks for the reminder.

Well, if I’m ever going to afford any kind of retirement, I’d better go make myself useful again…