Shrek wrote:
Using the memory functions is a bit confusing as AMSPM does not correlate to the windows API all that well for example I was looking how to allocate a buffer then fill it with a string and get the pointer to use and get a pointer to a structure as defined in the winapi guides, looking at the button example I can sort of piece things together say:
__Memory.NewArray(RECT) is a pointer to an already defined rect structure.
__Memory.NewArray(_char) is a pointer to a buffer created by __Memory.StringToChararray(string.rep("\0",nLength+1))
but I cant seem to find out how to free off the buffers that I would be creating, any help?
Hi
this application created for AMS users and they usually used to use wizards and ready made actions
and design of this application was made based on this idea , this memory and dll functions are using metatables and garbage collectors
so ,you do not need to free/delete/dealocate anything , they will automatically deleted by garbage collector
making a DLL/Memory handling system like Memory plugins that you familiar , will make things harder for users of this application
all of types are compatible with Windows API functions as long as you used __DLL.GetFunction() with proper declaration
but i realized that making an advanced memory class would be very good , and i am going to add a new class to implement DLL handling in native way
Shrek wrote:
How do I get a pointer to a structure?
you will not need it in this program , because when you define a function with an argument as struct then everthing will be done automatically
Shrek wrote:Lets start again..................
How do I get the size of a structure?
currently there is no provided function to do that but you can easily multiply member sizes and then get actual size
Shrek wrote:
How do I free a structure?
it is automated simply it is subject to garbage collection , but you can use
variable = nil; to delete anything you want
this will call
__gc() metamethod of specified data and it will be freed
Shrek wrote:
How do I create a buffer of x amount of bytes?
actually you do not need to allocate buffer because this system does it for you and frees it when it is necessary
you will only need to allocate buffer for char arrays (string)
and you can make it like below ,this allocates a buffer in 100 characters length plus NULL
and fills buffer with NULLs
Code: Select all
local nLength = 100;
local buffer = __Memory.StringToChararray(string.rep("\0",nLength+1));
now you can pass buffer to any function that expects an argument like (char*) or derivatives
the above code is equivalent of the following
Code: Select all
char *buffer = malloc(sizeof(char)*100+1);
Shrek wrote:
How do I get a pointer to a buffer I created?
Code: Select all
local nLength = 100;
local buffer = __Memory.StringToChararray(string.rep("\0",nLength+1));
the variable
buffer is pointer to allocated buffer
Shrek wrote:
How do I free a buffer I created?
Code: Select all
local nLength = 100;
local buffer = __Memory.StringToChararray(string.rep("\0",nLength+1));
it is subject to garbage collection but , by above sample
buffer = nil will free it
Shrek wrote:
How do I put a string in a buffer I created?
you can make both at once
Code: Select all
local buffer = __Memory.StringToChararray("Hello World!!\0");
in above sample a buffer created and a string
Hello World!! is assigned to it
Shrek wrote:
How do I retrieve a string from a buffer I created then passed it over to the api to fill in?
Code: Select all
local buffer = __Memory.StringToChararray("Hello World!!\0");
local string_in_buffer = __Memory.ChararrayToString(buffer);
__Memory.StringToChararray() : allocates a buffer (array of char) and puts string in it
__Memory.ChararrayToString() : gets string in a buffer
Shrek wrote:
How do I use Unicode strings with buffers?
sorry currently not possible