1. Poke-ing memory allocated through Windows function
- Posted by Jonas Temple <jtemple at yhti.net> Feb 17, 2006
- 572 views
- Last edited Feb 18, 2006
All, Well, I fixed the code section I posted earlier to put HTML formatted text to the clipboard. No more memory problems so far (I'll post the updated code for any who are interested). What I'm curious about is: I thought Euphoria would not poke() to an address if it wasn't allocated through allocate(). In my clipboard code I had to use Window's GlobalAlloc to allocate the memory and then I wondered how to poke the data, either through another Windows function or poke(). I tried poke() and it worked. Can anyone clear this up for me? Jonas Temple http://www.yhti.net/~jktemple
2. Re: Poke-ing memory allocated through Windows function
- Posted by Jason Gade <jaygade at yahoo.com> Feb 17, 2006
- 531 views
- Last edited Feb 18, 2006
Jonas Temple wrote: > > All, > > Well, I fixed the code section I posted earlier to put HTML formatted text to > the clipboard. No more memory problems so far (I'll post the updated code for > any who are interested). > > What I'm curious about is: I thought Euphoria would not poke() to an address > if it wasn't allocated through allocate(). In my clipboard code I had to use > Window's GlobalAlloc to allocate the memory and then I wondered how to poke > the data, either through another Windows function or poke(). I tried poke() > and it worked. > > Can anyone clear this up for me? > > Jonas Temple > <a href="http://www.yhti.net/~jktemple">http://www.yhti.net/~jktemple</a> If you are using safe.e instead of machine.e, you have to register any blocks not returned by allocate(). Using the normal machine.e Euphoria will let you poke anywhere, but if the address you use doesn't belong to your application then Linux or Windows will give you a segmentation fault/access violation. See: http://www.rapideuphoria.com/lib_p_r.htm#register_block -- "Any programming problem can be solved by adding a level of indirection." --anonymous "Any performance problem can be solved by removing a level of indirection." --M. Haertel "Premature optimization is the root of all evil in programming." --C.A.R. Hoare j.
3. Re: Poke-ing memory allocated through Windows function
- Posted by Bernie Ryan <xotron at bluefrog.com> Feb 17, 2006
- 524 views
- Last edited Feb 18, 2006
Jonas Temple wrote: > > All, > > Well, I fixed the code section I posted earlier to put HTML formatted text to > the clipboard. No more memory problems so far (I'll post the updated code for > any who are interested). > > What I'm curious about is: I thought Euphoria would not poke() to an address > if it wasn't allocated through allocate(). In my clipboard code I had to use > Window's GlobalAlloc to allocate the memory and then I wondered how to poke > the data, either through another Windows function or poke(). I tried poke() > and it worked. > > Can anyone clear this up for me? > > Jonas Temple > <a href="http://www.yhti.net/~jktemple">http://www.yhti.net/~jktemple</a> You can poke in any memory that is owned by your program. When you used GlobalAlloc() you requested that the OS assign some memory to your program therefore you can poke in that allocated memory. The only thing I think that you will need to be careful of is to release that memory with the proper OS function because I don't think Euphoria will do that for you. Euphoria manages it own memory off the heap memory and releases it when Euphoria ends. Bernie My files in archive: WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, W32API Can be downloaded here: http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan
4. Re: Poke-ing memory allocated through Windows function
- Posted by jacques deschĂȘnes <desja at globetrotter.net> Feb 18, 2006
- 542 views
Hi Jonas, here the way to use global memory for clipboard usage
-- code sample atom hGlobal, pData -- allocate global memory with flags required by clipboard hGlobal = GlobalAlloc(32,GMEM_MOVEABLE) -- lock it to ensure the system don't move it while your program is accessing it. pData = GlobalLock(hGlobal) poke(pData,"hello world"&0) GlobalUnlock(hGlobal) SetClipboardData(CF_TEXT,hGlobal) . . . GlobalFree(hGlobal) -- free it with that function when no more needed.
regards, Jacques DeschĂȘnes