Raised This Month: $ Target: $400
 0% 

malloc in pawn?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hyper Nova
BANNED
Join Date: May 2012
Old 05-19-2012 , 10:41   malloc in pawn?
Reply With Quote #1

Hello, i need to know what is malloc in pawn,

I need to found this function but i did not found it in any include file.
However i search from google and it seems like there are not that function in pawn like malloc.

Can someone help me?
Hyper Nova is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 05-19-2012 , 10:47   Re: malloc in pawn?
Reply With Quote #2

Doesn't exist in AMXX Pawn.
__________________

Last edited by <VeCo>; 05-19-2012 at 11:00.
<VeCo> is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-19-2012 , 11:06   Re: malloc in pawn?
Reply With Quote #3

The only data size in pawn is cell (4 bytes), you can only declare variables that have that size or array of such type :

new var
new Float:var
new bool:var

All of them uses a cell.

You can declare arrays :

new string[32]
new bool:IsPlayerCheater[33]


Note that pawn let you declare char arrays doing : new array[128 char] but it is not supported by any amxx native.
You could use it anyway instead of player bool variable :

new bool:g_HasParachute[33]
-> g_HasParachute[player] = true , g_HasParachute[player] = false

Instead you can do :
new g_HasParachute[33 char]
g_HasParachute{id} = 1

It will use less memory.



If you don't want to allocate memory each time, consider using static variables inside functions, or global variables.
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 05-19-2012 at 11:09.
ConnorMcLeod is offline
t3hNox
Senior Member
Join Date: Oct 2009
Old 05-19-2012 , 13:08   Re: malloc in pawn?
Reply With Quote #4

I would like to clearify something.
In terms of memory usage it means creating Array[33 char] would be more efficient than Array[33] ?

However, creating a simple variable (new SomeVar) would be even more effecient than Array[33 char] if bit shifting is used to assign values to SomeVar (but for simple variables there is a strict limitation as to how many values can be assigned) ?

ConnorMcLeod mentioned that this char functionality is not supported by any amxx native yet I have seen plugins using arrays with chars without having any appearant problems. For example if I'm using iMoney[33 char] array to store every player's money, would it cause any problems (I'm simply talking about setting and retrieving values from array, not formatting or anything like that) ?

And lastly, would this work ?
new Array[95 char]
Array{83} = 235315
t3hNox is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-19-2012 , 13:27   Re: malloc in pawn?
Reply With Quote #5

Create [33 char] uses 33 bytes or memory, create [33] uses 132, though it's not a big deal nowadays, and also, i'm not sur but i think that a fix amount of memory is reserved to each plugin.
You can only set a value between 0 and 255, so you won't buy a lot of thing to such few money
When i said no native supports it, i meant this for strings.
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 05-19-2012 at 13:30.
ConnorMcLeod is offline
t3hNox
Senior Member
Join Date: Oct 2009
Old 05-19-2012 , 15:01   Re: malloc in pawn?
Reply With Quote #6

Ok, thanks.
t3hNox is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:01.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode