Raised This Month: $ Target: $400
 0% 

Strings...


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MaximusBrood
Veteran Member
Join Date: Sep 2005
Location: The Netherlands
Old 04-26-2006 , 09:24   Strings...
Reply With Quote #1

Q1.

If you initialise a string like this

Code:
new yeey[2][SOME_CONSTANT][3][128]

Can I check if [1][5][2] is empty by doing this?

Code:
if(!myString[0]) {    // ... }

---

Q2

If I do this in the global (outside any function)

Code:
new yeey[2][32][3][128]

Wouldn't it reserve an awfull lot of memory by doing this?
(24576 chars if I'm not mistaken, but I forgot how much an int takes)

Or am I totally wrong, since I read somewhere that declaring variables globally is free storage.
Should compare with C.
Code:
int *yay; yay = new int;
__________________
Released six formerly private plugins. Not active here since ages.
MaximusBrood is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 04-26-2006 , 09:30  
Reply With Quote #2

No, you have to use something like:

Code:
if(!yeey[2][SOME_CONSTANT][3][0]) {       // do my stuff }

Also, arrays are free storage, but Pawn zeroes each cell automatically. This is a huge CPU hit, so you should avoid making arrays that large if you can do it other ways.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
MaximusBrood
Veteran Member
Join Date: Sep 2005
Location: The Netherlands
Old 04-26-2006 , 09:34  
Reply With Quote #3

Lol, I took the if(!myString[0]) literally from another post.
Forgot to edit it to my needs

Thanks
__________________
Released six formerly private plugins. Not active here since ages.
MaximusBrood is offline
Greenberet
AMX Mod X Beta Tester
Join Date: Apr 2004
Location: Vienna
Old 04-26-2006 , 09:39  
Reply With Quote #4

Code:
new yeey[2][32][3][128]
for this array you need 96 KB or 192 KB of ram...
Code:
2 * 32 * 3 * 128 = 24.576 Bytes
so now multiply this with sizeof cell: 4 bytes( 32bit ) or 8 bytes( 64bit )
Code:
24.576 * 4 = 98,304 Bytes | 24.576 * 8 = 196.608 Bytes
now divide this by 1024 so we have the KB
Code:
 98,304 / 1024 = 96 KB | 196.608 / 1024 = 192 KB
edit:
stupid mistake
Greenberet is offline
Send a message via ICQ to Greenberet Send a message via MSN to Greenberet
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 04-26-2006 , 09:46  
Reply With Quote #5

Are you joking? It might be something like 192 kb, but if it was 192 mb then it would be impossible to do anything, there wouldn't be enough data on the computer.

Think logically.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 04-26-2006 , 09:59  
Reply With Quote #6

yea....byte go to KB before MB
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
MaximusBrood
Veteran Member
Join Date: Sep 2005
Location: The Netherlands
Old 04-26-2006 , 10:00  
Reply With Quote #7

Nice calculations GreenBeret

But, eh, 1 MB = 1048576 bytes

---

You calculations are perfectly correct until the final outcome:

Now divide this by 1024 so we have the KB
Code:
98,304 / 1024 = 96 KB | 196.608 / 1024 = 192 KB
__________________
Released six formerly private plugins. Not active here since ages.
MaximusBrood is offline
MaximusBrood
Veteran Member
Join Date: Sep 2005
Location: The Netherlands
Old 04-26-2006 , 10:12  
Reply With Quote #8

Allright, next question:

I have a string that can contain 5 arguments maximum:

%map%de_dust
%map%de_dust%min_players%12
%map%de_dust%min_players%12%max_players%12

How can I put each different argument into another place?

Map: de_dust
Map: de_dust AND Minimal Players: 12
Map: de_dust AND Minimal Players: 12 AND Maximal Players: 12

-*-

Parse can take an unkown amount of arguments, but I don't think it very suitable.
Can this work?

Code:
//I don't really know this part new amount = strfind(myString, "%") for(new a = 0; a < amount; a++) {     myString[0] = ' '     trim(myString)     strtok(myString, argumentsOwnPlace[0][a], 31, argumentsOwnPlace[1][a], 31, '%') }

Firstly I don't even know if strfind will return the number of occurences.
Secondly, I don't think it is very efficient. Does anyone else know a more efficient way to do this?
__________________
Released six formerly private plugins. Not active here since ages.
MaximusBrood is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 04-26-2006 , 10:21  
Reply With Quote #9

parse or strbreak is what you want, probably parse. parse will split each argument into a string. If they only give 2 args, that's ok, it'll just make the 3 last strings empty.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Greenberet
AMX Mod X Beta Tester
Join Date: Apr 2004
Location: Vienna
Old 04-26-2006 , 10:47  
Reply With Quote #10

oops sry^^
I forgot, that there is also the kb step
Greenberet is offline
Send a message via ICQ to Greenberet Send a message via MSN to Greenberet
Reply


Thread Tools
Display Modes

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 05:14.


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