<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: тонкости с потреблением памяти]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=15910&amp;type=atom" />
	<updated>2020-12-17T11:31:09Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=15910</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: тонкости с потреблением памяти]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=144234#p144234" />
			<content type="html"><![CDATA[<p>Да, прикольно.<br />Только в этой теме хотелось бы обсуждать тонкости с потреблением памяти.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2020-12-17T11:31:09Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=144234#p144234</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: тонкости с потреблением памяти]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=144233#p144233" />
			<content type="html"><![CDATA[<p>Простой способ открыть pdf в GUI: <a href="https://www.autohotkey.com/boards/viewtopic.php?p=370626#p370626">https://www.autohotkey.com/boards/viewt … 26#p370626</a></p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2020-12-17T10:51:08Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=144233#p144233</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: тонкости с потреблением памяти]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=144109#p144109" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Malcev пишет:</cite><blockquote><p>Следующий код загружает pdf в gui</p></blockquote></div><p>Ну, всё-таки не pdf, а картинку, сделанную из pdf-страницы. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2020-12-11T09:05:39Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=144109#p144109</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: тонкости с потреблением памяти]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=144108#p144108" />
			<content type="html"><![CDATA[<p>Следующий код загружает pdf в gui.<br /></p><div class="codebox"><pre><code>pdfPath := &quot;D:\1064754760.pdf&quot;

VarSetCapacity(GUID, 16)
DllCall(&quot;ole32\CLSIDFromString&quot;, &quot;wstr&quot;, IID_RandomAccessStream := &quot;{905A0FE1-BC53-11DF-8C49-001E4FC686DA}&quot;, &quot;ptr&quot;, &amp;GUID)
DllCall(&quot;ShCore\CreateRandomAccessStreamOnFile&quot;, &quot;wstr&quot;, pdfPath, &quot;uint&quot;, Read := 0, &quot;ptr&quot;, &amp;GUID, &quot;ptr*&quot;, IRandomAccessStream)
CreateClass(&quot;Windows.Data.Pdf.PdfDocument&quot;, IPdfDocumentStatics := &quot;{433A0B5F-C007-4788-90F2-08143D922599}&quot;, PdfDocumentStatics)
DllCall(NumGet(NumGet(PdfDocumentStatics+0)+8*A_PtrSize), &quot;ptr&quot;, PdfDocumentStatics, &quot;ptr&quot;, IRandomAccessStream, &quot;ptr*&quot;, PdfDocument)   ; LoadFromStreamAsync
WaitForAsync(PdfDocument)
DllCall(NumGet(NumGet(PdfDocument+0)+6*A_PtrSize), &quot;ptr&quot;, PdfDocument, &quot;uint&quot;, 0, &quot;ptr*&quot;, PdfPage)   ; GetPage
DllCall(&quot;Ole32\CreateStreamOnHGlobal&quot;, &quot;ptr&quot;, 0, &quot;uint&quot;, true, &quot;ptr*&quot;, IStream)
DllCall(&quot;ShCore\CreateRandomAccessStreamOverStream&quot;, &quot;ptr&quot;, IStream, &quot;uint&quot;, BSOS_DEFAULT := 0, &quot;ptr&quot;, &amp;GUID, &quot;ptr*&quot;, IRandomAccessStreamOut)
DllCall(NumGet(NumGet(PdfPage+0)+6*A_PtrSize), &quot;ptr&quot;, PdfPage, &quot;ptr&quot;, IRandomAccessStreamOut, &quot;ptr*&quot;, asyncInfo)   ; RenderToStreamAsync
WaitForAsync(asyncInfo)

DllCall(&quot;LoadLibrary&quot;, &quot;str&quot;, &quot;gdiplus&quot;)
VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1)
DllCall(&quot;gdiplus\GdiplusStartup&quot;, &quot;ptr*&quot;, pToken, &quot;ptr&quot;, &amp;si, &quot;ptr&quot;, 0)
DllCall(&quot;gdiplus\GdipCreateBitmapFromStream&quot;, &quot;ptr&quot;, IStream, &quot;ptr*&quot;, pBitmap)
DllCall(&quot;gdiplus\GdipCreateHBITMAPFromBitmap&quot;, &quot;ptr&quot;, pBitmap, &quot;ptr*&quot;, hBitmap, &quot;uint&quot;, 0xffffffff)
Gui, Add, Picture, , HBITMAP:%hBitmap%
Gui, Show

DllCall(&quot;Gdiplus.dll\GdipDisposeImage&quot;, &quot;ptr&quot;, pBitmap)
Close := ComObjQuery(IRandomAccessStream, IClosable := &quot;{30D5A829-7FA4-4026-83BB-D75BAE4EA99E}&quot;)
DllCall(NumGet(NumGet(Close+0)+6*A_PtrSize), &quot;ptr&quot;, Close)   ; Close
ObjRelease(Close)
ObjRelease(IRandomAccessStream)
ObjRelease(PdfDocumentStatics)
ObjRelease(PdfDocument)
ObjRelease(PdfPage)
ObjRelease(IStream)
Close := ComObjQuery(IRandomAccessStreamOut, IClosable := &quot;{30D5A829-7FA4-4026-83BB-D75BAE4EA99E}&quot;)
DllCall(NumGet(NumGet(Close+0)+6*A_PtrSize), &quot;ptr&quot;, Close)   ; Close
ObjRelease(Close)
ObjRelease(IRandomAccessStreamOut)




CreateClass(string, interface, ByRef Class)
{
   CreateHString(string, hString)
   VarSetCapacity(GUID, 16)
   DllCall(&quot;ole32\CLSIDFromString&quot;, &quot;wstr&quot;, interface, &quot;ptr&quot;, &amp;GUID)
   result := DllCall(&quot;Combase.dll\RoGetActivationFactory&quot;, &quot;ptr&quot;, hString, &quot;ptr&quot;, &amp;GUID, &quot;ptr*&quot;, Class, &quot;uint&quot;)
   if (result != 0)
   {
      if (result = 0x80004002)
         msgbox No such interface supported
      else if (result = 0x80040154)
         msgbox Class not registered
      else
         msgbox error: %result%
      ExitApp
   }
   DeleteHString(hString)
}

CreateHString(string, ByRef hString)
{
    DllCall(&quot;Combase.dll\WindowsCreateString&quot;, &quot;wstr&quot;, string, &quot;uint&quot;, StrLen(string), &quot;ptr*&quot;, hString)
}

DeleteHString(hString)
{
   DllCall(&quot;Combase.dll\WindowsDeleteString&quot;, &quot;ptr&quot;, hString)
}

WaitForAsync(ByRef Object)
{
   AsyncInfo := ComObjQuery(Object, IAsyncInfo := &quot;{00000036-0000-0000-C000-000000000046}&quot;)
   loop
   {
      DllCall(NumGet(NumGet(AsyncInfo+0)+7*A_PtrSize), &quot;ptr&quot;, AsyncInfo, &quot;uint*&quot;, status)   ; IAsyncInfo.Status
      if (status != 0)
      {
         if (status != 1)
         {
            DllCall(NumGet(NumGet(AsyncInfo+0)+8*A_PtrSize), &quot;ptr&quot;, AsyncInfo, &quot;uint*&quot;, ErrorCode)   ; IAsyncInfo.ErrorCode
            msgbox AsyncInfo status error: %ErrorCode%
            ExitApp
         }
         ObjRelease(AsyncInfo)
         break
      }
      sleep 10
   }
   DllCall(NumGet(NumGet(Object+0)+8*A_PtrSize), &quot;ptr&quot;, Object, &quot;ptr*&quot;, ObjectResult)   ; GetResults
   ObjRelease(Object)
   Object := ObjectResult
}</code></pre></div><p>Если делать это в цикле, то идет утечка памяти, так как не освобождаются ресурсы IRandomAccessStream.<br /><a href="https://docs.microsoft.com/en-us/uwp/api/windows.storage.streams.irandomaccessstream?view=winrt-19041">https://docs.microsoft.com/en-us/uwp/ap … inrt-19041</a><br />Лечится с помощью:<br /></p><div class="codebox"><pre><code>DllCall(&quot;psapi.dll\EmptyWorkingSet&quot;, &quot;ptr&quot;, -1)</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2020-12-11T08:42:44Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=144108#p144108</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[AHK: тонкости с потреблением памяти]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=144107#p144107" />
			<content type="html"><![CDATA[<p>Здесь предлагаю делиться ситуациями странного потребления памяти и вариантами их предотвращения.<br />Сегодня столкнулся с интересной особенностью, что после встраивания своего гуи с WMPlayer.OCX в чужое окно через SetParent и разрушении чужого окна, GPU память продолжала съедаться.<br />Вылечилось отлавливанием закрытия окна и вызовом метода Controls.stop.<br /><a href="https://docs.microsoft.com/en-us/windows/win32/wmp/controls-stop">https://docs.microsoft.com/en-us/window … trols-stop</a><br />Странно, что такое происходило только с одной конкретной программой.</p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2020-12-11T08:38:45Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=144107#p144107</id>
		</entry>
</feed>
