Web Design and Web Development Forum

  1. #1
    vento's Avatar
    Join Date
    May 2009
    Location
    Lithuania
    Age
    18
    Posts
    185
    Rep Power
    3
  2. vento is on a distinguished road
  3. Why to free variables?

    Hello. I see people freeing variables before quitting, but is there a need? I think Windows (other OSes should do the same I guess) frees the RAM, so doesn't it free lower memory? (as I know variables are saved there, maybe I'm wrong) Maybe some libraries (OpenGL, SDL, Direct3D etc.) which use graphics card may require to free the memory (maybe OS doesn't free that memory), only?

    I just don't know a lot about that, so would be nice if you told me something about it, as I tried to look for the reason to free variables on exit on Google.

    Edited: I just want to add an additional question. I didn't want to create another topic as this is all about statistic, no discussions. Array vs Pointer, what is better or is it the same? I know that array is easier to read, easier to reach (multidimensional array is way easier to read (the code is more readable) than a pointer instead of it (e.g. a map array vs a pointer instead of it)), but what's about the speed/memory? I think memory should be nearly the same, but the most important is the speed, anyone has tested?
    Reply With Quote Reply With Quote
  4. #2
    Join Date
    May 2009
    Location
    NASHIK
    Posts
    19
    Rep Power
    0
  5. la_89ondevg is on a distinguished road
  6. Re: Why to free variables?

    well vento its a godd practice for free up variables for performance factor and for security as well otherwise someone could use the idle variable for getting into to red or manipulate the instructions in the text segment during compilation or during execution or using the library and for the second question both both of the array and pointer have their own adavntage so if you dont have to manage a 1000 records you can use an array as per condition that the number of data needed is varying but pointer saves the memory if you working with application req
    Reply With Quote Reply With Quote
  7. #3
    Join Date
    May 2009
    Posts
    7
    Rep Power
    0
  8. javascripter is on a distinguished road
  9. Smile Re: Why to free variables?

    Quote vento originally posted: View Post
    Edited: I just want to add an additional question. I didn't want to create another topic as this is all about statistic, no discussions. Array vs Pointer, what is better or is it the same? I know that array is easier to read, easier to reach (multidimensional array is way easier to read (the code is more readable) than a pointer instead of it (e.g. a map array vs a pointer instead of it)), but what's about the speed/memory? I think memory should be nearly the same, but the most important is the speed, anyone has tested?
    Those are two different data type( if I can call pointer a data type, but whatever ).

    Basically, pointers are very useful when you are working with a lot of memory. For example, in 2D game, class Map is a class that containts a lot of data( chests, character x and y positions, npc positions, tile positions,... ). Now, lets pretend that you have a function which takes an object of class Map as parameter. Like this: function_name( Map map );
    Now, if you would pass map( assuming that this is the main map your 2D game is using and that you have declared it before as object of class Map ) as an argument to that function( this is called passing by value ), all the contents of the object map would be copied temporary for use in that function. That would take a lot of memory and speed.

    Now, if you would use a pointer as an argument( assuming that you have overloaded function_name( Map map ); with function_name( Map *map ); ), content of the map wouldn't be copied thus saving a lot of speed and time.

    I would also suggest you to read more here:
    Direct Link.

    Actual URL - The Chaos Rift • View topic - Pointers...What is the point? .
    Reply With Quote Reply With Quote

Similar Threads

  1. Collect 27 ebook learn php
    By quyvphan in forum PHP Articles
    Replies: 1
    Last Post: 04-23-2009, 05:52 PM
  2. PHP Variables
    By NedreN in forum PHP Articles
    Replies: 12
    Last Post: 05-14-2008, 03:26 AM
  3. Comparison between Free web hosting and Paid Web Hosting
    By paul123 in forum Web Hosting Help
    Replies: 2
    Last Post: 02-24-2006, 07:09 PM
  4. ASP Variables
    By wizard in forum General Web Programming
    Replies: 0
    Last Post: 01-02-2005, 08:33 AM