Tuesday, December 18, 2007

2d lines intersection point & Linear equations

Do you remember 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 .

Wednesday, December 12, 2007

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. :)