Are you really sure that knowing the page size allows you to make a better choice on how to allocate your memory? If so, are you sure that C# is the best technology to develop your solution? Would you mind posting an example where knowing the page size would benefit you in your allocation of memory?
–
Kiley NaroOct 21 '11 at 13:57

Please see my sample code. As you can see here byte[] buffer = new byte[4096]; 4096 is hardcoded. I need to use the correct value here for example in cases of MS Windows 7 x86 and x64
–
DimiOct 21 '11 at 14:18

I must also add that allocating an array of page-size bytes is not the best choice.

First of all, C# memory can be moved, C# uses a compacting generational garbage collector.
There is not any kind of information on where data will be allocated.

Second, arrays in C# can be formed by non-contiguous area of memory! Arrays are stored contiguously in virtual memory but contiguous virtual memory is not contiguous physical memory.

Third, array data structure in C# occupies some bytes more than the content itself (it stores array size and other informations). If you allocate page size amount of bytes, using the array will switch page almost always!

I would think that this optimization can be an non-optimization.

Usually C# arrays performs very well without the need to split memory using page size.

If you really need precise allocation of data you need to use pinned arrays or Marshal allocation, but this will slow down the garbage collector.

I would say it is better to just use your arrays without thinking too much about the page size.