Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
I have stored a bigbitmap.bmp in memory (assume its size 640x4800), I want to see part of it in k loop where k< X. In the loop when k=0 I will see the first part of the bigbitmap.bmp that totally fits (the part) my screen at 640x480 in this typical example the limit of the loop is k<10
i want to create the
bigbitmap.bmp
as big as i can the value X depends on the
the total free bytes available, most likley in the memory based on
X=Total_Bytes_Availabel/(640x480)

how could i find
Total_Bytes_Availabel ? 


What I have tried:

Graphics g = pictureBox1.CreateGraphics();
     Rectangle SmallRect
     Bitmap SmallBitMap;
     Point p0_BigBitMap = new Point(1, 1);
     //X=Total_Bytes_Availabel/(640x480)
         for (k= 0;k< X;k++)
         {
             SmallRect = new Rectangle(p0_BigBitMap.X, p0_BigBitMap.Y, pictureBox1.Width , pictureBox1.Height);
             SmallBitMap = BigBitMap.Clone(SmallRect, BigBitMap.PixelFormat);
             g.DrawImage(SmallBitMap, p0_Picture);
             p0_BigBitMap.Y = p0_BigBitMap.Y + pictureBox1.Height;
         }
Posted
Updated 28-Jan-22 1:27am
v14

1 solution

System memory is a bit complex and virtual memories make it more complex.

For the start you can use below code to get Installed Memory. For my laptop it is showing 16 GB which is correct.
C#
var gcMemoryInfo = GC.GetGCMemoryInfo();
var installedMemory = gcMemoryInfo.TotalAvailableMemoryBytes;
// it will give the size of memory in MB
var physicalMemory = (double)installedMemory / 1048576.0;

You can get further details from below

How to get memory available or used in C# - Stack Overflow[^]

I was thinking of writing a bit detail over memory but then I found a great codeproject article that explains memory and their utilization in great length. You need to read the whole article with a cup of tea, will make your life easier.

Memory Limits in a .NET Process[^]
 
Share this answer
 
v3
Comments
Sean Ewington 28-Jan-22 7:57am    
Thanks very much for your answer. While the link you've shared may be exactly the answer OP needs, we ask that answers be self-contained. The issue with links is that over time, they break. Using a link as a reference is fine, but we ask that the bulk of the answer be available here.
_Asif_ 28-Jan-22 9:11am    
Acknowledged! I will update as soon as I get time
Engineer khalid 28-Jan-22 10:51am    
MemoryStream memStream = new MemoryStream(X);
I guess I am looking for this value X.
may be some thing like memStream.bufferMaxSize
Engineer khalid 28-Jan-22 11:15am    
i am not sure about this
static void Main()
{ int count;
long memBefore = GC.GetTotalMemory(true);
Console.WriteLine("memBefore = {0}\n", memBefore.ToString());
Console.ReadLine();
}
i get memBefore = 480384
Engineer khalid 28-Jan-22 11:40am    
480384 is the size used
i should read more in memory,still waitting for help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900