msnkd's profilePoor programmer's BlogPhotosBlogListsMore Tools Help

Blog


    December 26

    Global objects and CRT startup.

     
    Did you ever noticed about the initialization of your global objects ? Like who calls constructor and destructor of your global objects ?
    It is CRT does the job. Try changing the startup routine ( Linker settings in VS). You can see default it is blank . No startup routine is selcted. Infact it calls the __tmainCRTStartup in crt , and from the main get called.
     
    So try changing the startup routine to main ( not __tmainCRTStartup) , so you can see that the global objects
    constructors/Destructor are not get called.
     
    So you can make application more faster by removing startup rouinte to our main. But all other things we have to handle , anyway it is not generalized. 
     
    you can also set crt functions as startup routine. for example try setting malloc as startup routine ( you might get your pc hang).
     
    December 18

    2d lines intersection point & Linear equations

     
    Do you remeber the linear equations studied ? and methods to solve linear equations ?  may be some of us remember it.
     
    We know every line can be represented by a linear equation of the form Ax+by  =c . or in the point slope form y = mx + c.
    so if you have two lines in the graph  ( or in ur game) you can find the intersecting point by solving these equations. You can find the intersecting point by solving these equations.
     
    For example if you have two lines corresponding to , y = 2x,  and y = 0x+ 3 ( horizontal line ) so certainly these lines will intersect. .slopes are 2 and 0 respectily.
    so by solving these equations 2x-y =0 , and 0x + y = 3, we will get x = 3/2 and y = 3. 
     
    So what is the best method for solving linear equations using computers ? There are methods like
    1. Linear compostion (normal equation solving , by adding or subtracting 2 equations)
    2. gauss elimination method ( using matrixes. i think everybody knows it , no need for explanation. ).
    3. Cramer's Rule. ( creating the cofactor matrix and finding determinent , andby dividing with determinent).
     
    So which is the best ? I think gauss elimination is best. Because when the matrix diamension becomes bigger , cramer's method even takes days to find the answer.
    But gauss elimination method won't .
     
     
    December 12

    Reducing Heap Fragmentation with Low Fragment Heap Featuer

    Today most pc have enough memory . But there is still chance to occur fragmentation by continuously allocating and freeing small chunk of memory.
    Windows Xp , Windows Server 2003 has a new feature called Low fragment heap(LFH).

    If you enable this when creating heap , this can reduce heap fragmentation.
    The LFH has a predefines set of memory chunks of different sizes. it called this chunk as buckets , so when we request for a a few bytes , the LFH returns the bucket of smallest size. 

    The LFH option can be enable by the API HeapSetInformation. For example it may look like

    long HeapFragValue = 2;
    HeapSetInformation( GetProcessHeap(),HeapCompatibilityInformation,HeapFragValue,sizeof(HeapFragValue) );

    2 indicates the information is about LFH.

    This feature is very useful. Otherwise you may need to write your own allocators and handle the memory pool.
    When writing allocator we need to think about the page size , number of page faults etc. and certainly it takes some time.

    So if you are in hurry try the LFH option. :)