Freeing memory after using a variable...
#1

In my system I had the need to create a
pawn Код:
new string[2500];
string...

After the code, I want that string to disappear from memory to free space, how can I do that? What default instruction/function do I have to use?
Reply
#2

Uhhm... wouldn't it be enough just to empty the string?
Reply
#3

After you used that string use
Код:
string[ 0 ] = EOS;
Reply
#4

Thanks to both
Reply
#5

It automatically gets deallocated when the code block it is in is finished, like when you return from the function you use it in. Thats the system behind the stack.
Reply
#6

Quote:
Originally Posted by ******
Посмотреть сообщение
Using the stack is your best bet, although for an array that big I'd say either examine your code to see if you really need it (you can most likely do it a different way)
pawn Код:
new string[2500];
    new str2[51];
    for(new i; i < sizeof(GTA_VehicleNames); i++)
    {
        format(str2, 51, GTA_VehicleNames[i]);
        format(string, 2500, "%s%s\n", string, str2);
    }
    ShowPlayerDialog(playerid, DIALOG_VEH_SELECT, DIALOG_STYLE_LIST, "Vehicles:", string, "OK", "Cancel");
If I don't use a string of 2500 bytes, how can I put all the vehicle names into the dialog? This way was tested and it worked, but I'm not sure if it's the best way.
Reply
#7

Quote:
Originally Posted by ******
Посмотреть сообщение
Does that vehicle names array ever change? If not, do you really need to format the string every time or can you just make a constant string with all the vehicle names in it already?
Do you mean something like this?:

pawn Код:
#define GTAVehicles "Landstalker\nBravura\nBuffalo\nLinerunner\nPerrenial\nSentinel\nDumper" // ... To 200 more vehicle names
Reply
#8

Quote:
Originally Posted by ******
Посмотреть сообщение
But still you could just format it once on mode init.
Thanks, that's a great idea

pawn Код:
new vehicle_string[2500];

public OnFilterScriptInit()
{
    new str2[51];
    for(new i; i < sizeof(GTA_VehicleNames); i++)
    {
        format(str2, 51, GTA_VehicleNames[i]);
        format(vehicle_string, 2500, "%s%s\n", vehicle_string, str2);
    }
    return 1;
}

stock VehicleSpawner(playerid)
{
    ShowPlayerDialog(playerid, DIALOG_VEH_SELECT, DIALOG_STYLE_LIST, "Vehicles:", vehicle_string, "OK", "Cancel");
    return 1;
}
Reply
#9

Quote:
Originally Posted by ******
Посмотреть сообщение
Yeah, only you wouldn't be able to use a define (and actually I'm not sure you could do it any way thinking about it due to PAWN line length limits. But still you could just format it once on mode init.
It can be seprated by '\', for example i used

pawn Код:
#define STORE_DIALOG "Sprunk $50\nDice 20$\nSeeds 100$\nChemicals 100$\nMask 500$\nCellphone 100$"
#define GUNSHOP_DIALOG "Colt 45 - $700\nDesert Eagle - $2000\nShotgun - $1500\nSawnoff - $3000\nUzi - $1250\nTec-9 - $1200\nRifle - $900\nAK47 - $3100\nKevlar - $1000"
#define LSPD_DIALOG "Nightstick 20$\nPepper Spray $30\nColt 45 - $100\nDesert Eagle - $200\nShotgun - $150\nSniper Rifle - $200\nMP5 - $200\nM4A1 - $250\nKevlar - $50"

#define JEFFERSON1_DIALOG "BMX (10000) (Vehicle ID: 481) (( Time: 7 ))\nBike (10000) (Vehicle ID: 509) (( Time: 7 ))\nMountain Bike (10000) (Vehicle ID: 510) (( Time: 7 ))\nMower (15000) (Vehicle ID: 572) (( Time: 7 ))\nKart (20000) (Vehicle ID: 571) (( Time: 7 ))\nFaggio (20000) (Vehicle ID: 462) (( Time: 7 ))\nNext"
#define JEFFERSON2_DIALOG "Freeway (35000) (Vehicle ID: 463) (( Time: 20 ))\nSanchez (40000) (Vehicle ID: 468) (( Time: 20 ))\nCamper (45000) (Vehicle ID: 483) (( Time: 24 ))\nClover (45000) (Vehicle ID: 524) (( Time: 24 ))\nPCJ-600 (50000) (Vehicle ID: 461) (( Time: 24 ))\nWayfarer (50000) (Vehicle ID: 586) (( Time: 24 ))\nFCR-900 (55000) (Vehicle ID: 521) (( Time: 24 ))\nNext\nBack"
#define JEFFERSON3_DIALOG "Tampa (55000) (Vehicle ID: 549) (( Time: 24 ))\nSabre (60000) (Vehicle ID: 543) (( Time: 28 ))\nVincent (60000) (Vehicle ID: 540) (( Time: 28 ))\nMajestic (60000) (Vehicle ID: 517) (( Time: 28 ))\nPicador (60000) (Vehicle ID: 600) (( Time: 28 ))\nVoodoo (60000) (Vehicle ID: 412) (( Time: 28 ))\nTornado (65000) (Vehicle ID: 576) (( Time: 28 ))\nNext\nBack"
#define JEFFERSON4_DIALOG "Buccaneer (65000) (Vehicle ID: 518) (( Time: 28 ))\nPremier (70000) (Vehicle ID: 426) (( Time: 32 ))\nTahoma (70000) (Vehicle ID: 566) (( Time: 32 ))\nSadler (70000) (Vehicle ID: 422) (( Time: 32 ))\nBobcat (70000) (Vehicle ID: 422) (( Time: 32 ))\nGlendale (70000) (Vehicle ID: 604) (( Time: 32 ))\nMesa (70000) (Vehicle ID: 500) (( Time: 32 ))\nNext\nBack"
#define JEFFERSON5_DIALOG "Regina (70000) (Vehicle ID: 479) (( Time: 32 ))\nBroadway (70000) (Vehicle ID: 575) (( Time: 32 ))\nHermes (75000) (Vehicle ID: 474) (( Time: 36 ))\nFortune (75000) (Vehicle ID: 526) (( Time: 36 ))\nGreenwood (80000) (Vehicle ID: 492) (( Time: 36 ))\nBlade (80000) (Vehicle ID: 536) (( Time: 36 ))\nStratum (80000) (Vehicle ID: 561) (( Time: 36 ))\nNext\nBack"
#define JEFFERSON6_DIALOG "Washington (80000) (Vehicle ID: 421) (( Time: 36 ))\nNebula (80000) (Vehicle ID: 516) (( Time: 36 ))\nSentinel (80000) (Vehicle ID: 405) (( Time: 36 ))\nMerit (80000) (Vehicle ID: 551) (( Time: 36 ))\nBurrito (80000) (Vehicle ID: 482) (( Time: 36 ))\nFeltzer (85000) (Vehicle ID: 533) (( Time: 44 ))\nHustler (85000) (Vehicle ID: 545) (( Time: 44 ))\nNext\nBack"
#define JEFFERSON7_DIALOG "Remmington (90000) (Vehicle ID: 534) (( Time: 44 ))\nAdmiral (90000) (Vehicle ID: 445) (( Time: 44 ))\nWindsor (90000) (Vehicle ID: 555) (( Time: 44 ))\nSunrise (90000) (Vehicle ID: 550) (( Time: 44 ))\nVirgo (90000) (Vehicle ID: 491) (( Time: 44 ))\nSavanna (100000) (Vehicle ID: 567) (( Time: 50 ))\nLandstalker (100000) (Vehicle ID: 400) (( Time: 50 ))\nNext\nBack"
#define JEFFERSON8_DIALOG "Stafford (105000) (Vehicle ID: 580) (( Time: 50 ))\nHuntley (05000) (Vehicle ID: 579) (( Time: 50 ))\nRancher (105000) (Vehicle ID: 489) (( Time: 50 ))\nYosemite (105000) (Vehicle ID: 554) (( Time: 50 ))\nSlamvan (110000) (Vehicle ID: 535) (( Time: 56 ))\nTanker (120000) (Vehicle ID: 514) (( Time: 100 ))\nLinerunner (120000) (Vehicle ID: 403) (( Time: 100 ))\nNext\nBack"
#define JEFFERSON9_DIALOG "Journey (120000) (Vehicle ID: 508) (( Time: 100 ))\nNRG-500 (150000) (Vehicle ID: 522) (( Time: 1000 ))\nBack"

#define RODEO1_DIALOG "Blista Compact (120000) (Vehicle ID: 496) (( Time: 60 ))\nAlpha (130000) (Vehicle ID: 602) (( Time: 70 ))\nBuffalo (150000) (Vehicle ID: 402) (( Time: 92 ))\nUranus (150000) (Vehicle ID: 558) (( Time: 92 ))\nHotknife (150000) (Vehicle ID: 434) (( Time: 92 ))\nPhoenix (160000) (Vehicle ID: 603) (( Time: 106 ))\nNext"
#define RODEO2_DIALOG "Flash (160000) (Vehicle ID: 565) (( Time: 106 ))\nZR-350 (170000) (Vehicle ID: 477) (( Time: 110 ))\nEuros (180000) (Vehicle ID: 587) (( Time: 118 ))\nElegy (200000) (Vehicle ID: 562) (( Time: 130 ))\nSuper GT (210000) (Vehicle ID: 506) (( Time: 140 ))\nJester (210000) (Vehicle ID: 559) (( Time: 150 ))\nNext\nBack"
#define RODEO3_DIALOG "Comet (250000) (Vehicle ID: 480) (( Time: 180 ))\nCheetah (350000) (Vehicle ID: 415) (( Time: 220 ))\nSultan (370000) (Vehicle ID: 560) (( Time: 240 ))\nBanshee (400000) (Vehicle ID: 429) (( Time: 260 ))\nHotring Racer (400000) (Vehicle ID: 494) (( Time: 1000 ))\nHotring Racer (400000) (Vehicle ID: 502) (( Time: 1000 ))\nNext\nBack"
#define RODEO4_DIALOG "Bullet (450000) (Vehicle ID: 541) (( Time: 320 ))\nTurismo (475000) (Vehicle ID: 451) (( Time: 360 ))\nInfernus (500000) (Vehicle ID: 411) (( Time: 380 ))\nBack"
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)