AW: Memory access plugin -
BigETI - 20.01.2015
Yes.
MEM::calloc() sets to zero, and
MEM::malloc() leaves it as it was (what you actually can read after
MEM::malloc() is data garbage left from previous accesses).
Re: Memory access plugin -
PaulDinam - 20.01.2015
Sorry for asking too much but let's say I have something like this:
pawn Код:
MEM::struct e_TEXT
{
Message[100]
};
new Pointer:Texts[MAX_PLAYERS][MAX_TEXT_MESSAGES];
And my testing commands:
pawn Код:
CMD:on(playerid, params[])
{
Texts[playerid][strval(params)] = MEM::calloc(e_TEXT);
return 1;
}
CMD:off(playerid, params[])
{
Texts[playerid][strval(params)] = Pointer:NULL;
return 1;
}
CMD:show(playerid, params[])
{
MEM_MACR_foreach(MAX_TEXT_MESSAGES, i)
{
if(Texts[playerid][i])
{
MEM::get_arr(Texts[playerid][i], Message, msg, 100);
SCMEx(playerid, -1, "%s", msg);
}
}
return 1;
}
When I try to set a specific index to a Pointer:NULL; it says it must be assigned to an array.
AW: Memory access plugin -
BigETI - 21.01.2015
CMD:on does allocate memory, and calling it again will cause
leaking memory.
Using strval(params) without checks is not a good idea IMO.
CMD:off just sets the pointer to zero, which is bad, because the allocated memory is still allocated and you just lost the reference to it. See
https://sampwiki.blast.hk/wiki/Memory_ac...in#Memory_leak
Use
MEM:free to de-allocate it and set the pointer to NULL, so you won't cause leaking memory at all.
If you can't use NULL, because some other include may already defined it, you can use
Pointer:0 or define
MEM_NULL_EX before including
memory.inc, so you can use
Pointer:MEM_EX::NULL for the same result.
Re: Memory access plugin -
PaulDinam - 21.01.2015
I understand, it was just for testing purposes anyway.
So using calloc() in CMD: on every time will cause memory leak even after I set a pointer to null and free it?
Here's what I did using memory allocation: (not sure if it's written properly or has any memory leaking)
http://pastebin.com/ApQiGUNR
And when a player disconnects:
pawn Код:
MEM_MACR_foreach(MAX_TEXT_MESSAGES, i) // Text messages
{
MEM::free(Texts[playerid][i]);
Texts[playerid][i] = Pointer:0;
}
Connect
pawn Код:
MEM_MACR_foreach(MAX_TEXT_MESSAGES, i) // Text messages
{
Texts[playerid][i] = MEM::calloc(e_TEXT);
}
AW: Memory access plugin -
BigETI - 21.01.2015
allocating at connection and freeing at disconnection is fine. Using this method you don't need further allocation and de-allocation at your command functions, and your memory is fine.
Re: Memory access plugin -
PaulDinam - 23.01.2015
Is there a way to set a float variable?
AW: Memory access plugin -
BigETI - 23.01.2015
Yes, for example:
Setting values:
pawn Код:
#define MEM_set_val_ex(%0,%1,%2) (Float:(MEM_set_val(%0, %1, _:(%2))))
// ...
MEM::set_val_ex(ptr, _, 4.0);
// or...
new Float:p = 4.0;
MEM::set_val_ex(ptr, _, p);
Getting values
pawn Код:
#define MEM_get_float(%0) (Float:(MEM_get_val(%0)))
// ...
printf("%f", MEM::get_float(ptr));
Setting values by using structures:
pawn Код:
#define MEM_set_val_ex(%0,%1,%2) (Float:(MEM_set_val(%0, %1, _:(%2))))
MEM::struct Vect3D
{
Float:Vect3D_X,
Float:Vect3D_Y,
Float:Vect3D_Z
}
// ...
MEM::set_val_ex(ptr, Vect3D_X, 2.0);
MEM::set_val_ex(ptr, Vect3D_Y, 3.0);
MEM::set_val_ex(ptr, Vect3D_Z, 4.0);
// or...
new Float:x = 2.0, Float:y = 3.0, Float:z = 4.0f;
// ...
MEM::set_val_ex(ptr, Vect3D_X, x);
MEM::set_val_ex(ptr, Vect3D_Y, y);
MEM::set_val_ex(ptr, Vect3D_Z, z);
// or...
new pos[Vect3D] = {2.0, 3.0, 4.0};
MEM::set_arr(ptr, _, pos);
Getting values by using structures:
pawn Код:
MEM::struct Vect3D
{
Float:Vect3D_X,
Float:Vect3D_Y,
Float:Vect3D_Z
}
// ...
printf("{ %f, %f, %f }", MEM_get_val(ptr, Vect3D_X), MEM_get_val(ptr, Vect3D_Y), MEM_get_val(ptr, Vect3D_Z));
Re: Memory access plugin -
PaulDinam - 23.01.2015
Appreciated mate.
Re: Memory access plugin -
WopsS - 03.02.2015
You should add a CensOS version.
Anyway thank you for this plugin
Re: Memory access plugin -
Yousha - 16.09.2017
Files Not found.
Re: Memory access plugin -
DimaShift - 30.09.2017
when I put this plugin
the server runs a bit and then shutdown
Re: Memory access plugin -
BigETI - 05.10.2017
I am sorry that the links have expired over the years. I have to relocate all my releases, create a build system, make some builds and update my threads over the next days. Please be patient.
Links are still working, kek.
Re: Memory access plugin -
DimaShift - 16.10.2017
Quote:
Originally Posted by BigETI
I am sorry that the links have expired over the years. I have to relocate all my releases, create a build system, make some builds and update my threads over the next days. Please be patient.
Links are still working, kek.
|
I am guilty! I made some mistakes!
This plugin is great ++
[OBSOLETE] Memory access plugin -
BigETI - 23.11.2017
This plugin is obsolete. I recommend to switch to
https://sampforum.blast.hk/showthread.php?tid=645166