AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Strings... (https://forums.alliedmods.net/showthread.php?t=27648)

MaximusBrood 04-26-2006 09:24

Strings...
 
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;

Hawk552 04-26-2006 09:30

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.

MaximusBrood 04-26-2006 09:34

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

Thanks :D

Greenberet 04-26-2006 09:39

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

Hawk552 04-26-2006 09:46

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.

Xanimos 04-26-2006 09:59

yea....byte go to KB before MB

MaximusBrood 04-26-2006 10:00

Nice calculations GreenBeret :D

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

MaximusBrood 04-26-2006 10:12

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?

Hawk552 04-26-2006 10:21

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.

Greenberet 04-26-2006 10:47

oops sry^^
I forgot, that there is also the kb step :oops:


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

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