Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

TrimRamProcess

In the context of RAM, memory trimming (or trimming memory) refers to the process of reclaiming unused memory from a process's allocated memory space and returning it to the operating system.

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

:computer: TrimRamProcess:

"Trim" in the context of computer memory (RAM) refers to a process that reclaims unused memory, making it available for other processes. It's particularly relevant for Solid State Drives (SSDs) where it helps maintain performance and longevity. In the context of RAM, it's typically used to describe the process of releasing memory back to the operating system, often involving calls to malloc_trim() in environments like Vertica.

</br>

Compiler 10 Seattle 10 1 Berlin 10 2 Tokyo 10 3 Rio
10 4 Sydney 11 Alexandria 12 Athens
Components None

</br>

</br> </br>

Memory architecture describes the methods used to implement electronic computer data storage in a manner that is a combination of the fastest, most reliable, most durable, and least expensive way to store and retrieve information. Depending on the specific application, a compromise of one of these requirements may be necessary in order to improve another requirement. Memory architecture also explains how binary digits are converted into electric signals and then stored in the memory cells. And also the structure of a memory cell.

For example, dynamic memory is commonly used for primary data storage due to its fast access speed. However dynamic memory must be repeatedly refreshed with a surge of current dozens of time per second, or the stored data will decay and be lost. Flash memory allows for long-term storage over a period of years, but it is much slower than dynamic memory, and the static memory storage cells wear out with frequent use.

</br>

1. RAM & TRIM (or Memory Trimming):

Purpose:

In the context of RAM, memory trimming (or trimming memory) refers to the process of reclaiming unused memory from a process's allocated memory space and returning it to the operating system.

Mechanism:

A memory poller, for example in Vertica, might monitor memory usage and, when a certain threshold is reached, trigger malloc_trim() to release unused memory from the process's heap.

Example:

A Vertica database might use a memory poller to monitor memory allocated by malloc. If the amount of free memory within the allocated memory space (malloc) drops below a certain threshold compared to the total memory used by the process (RSS), malloc_trim() is called to reclaim unused memory.

Dask:

In Dask, a distributed computing framework, setting the MALLOC_TRIM_THRESHOLD_ environment variable to 0 or a low value can force memory trimming by the worker processes, though this can impact performance.

1. Other Contexts:

RAM Process (different meaning): In some contexts, "RAM process" can refer to the mechanical pressing of ceramic shapes using permeable dies, often with gypsum cement. MemoryExtensions.Trim (C#): The MemoryExtensions.Trim() method in C# is used to remove leading and trailing whitespace from a character memory region.

Memory leak

In computer science, a memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations in a way that memory which is no longer needed is not released. A memory leak may also happen when an object is stored in memory but cannot be accessed by the running code (i.e. unreachable memory). A memory leak has symptoms similar to a number of other problems and generally can only be diagnosed by a programmer with access to the program's source code.

A related concept is the "space leak", which is when a program consumes excessive memory but does eventually release it.

Because they can exhaust available system memory as an application runs, memory leaks are often the cause of or a contributing factor to software aging.

</br>

:speech_balloon: Code example

pascal
{ exact execution state of an application actively controlled
  by the integrated debugger }
procedure TForm1.DebugProcessStatus(s: string);
var
  pmc: PPROCESS_MEMORY_COUNTERS;
  cb: Integer;
  MemStat: tMemoryStatus;
  NewWorkingMemory, OldWorkingMemory : Longint;
  l_nSize: Cardinal;
  hProcess: THandle;
  ProcessID: DWORD;
  MyHandle: THandle;
  Struct: TProcessEntry32;
  Status: TMemoryStatusEx;
begin
  // returns the total memory size (in bytes)
  MemStat.dwLength := SizeOf(MemStat);
  // Retrieve system information regarding physical and virtual memory usage.
  GlobalMemoryStatus(MemStat);

  // Get the used memory for the current process
  cb := SizeOf(TProcessMemoryCounters);

  // transmit information
  GetMem(pmc, cb);
  pmc^.cb := cb;

  // transmission of the processed bytes and the lost ones
  if GetProcessMemoryInfo(GetCurrentProcess(), pmc, cb) then
  begin
    NewWorkingMemory           := Longint(pmc^.WorkingSetSize);
    Label27.Caption := FormatFloat('###,###', NewWorkingMemory / 1024) + ' bytes';
    Label28.Caption := FormatFloat('###,###', (NewWorkingMemory - OldWorkingMemory) / 1024) + ' bytes';
    OldWorkingMemory := NewWorkingMemory;
  end;

  // pass the bytes of the progress bars
  if (GetProcessMemorySize(Edit1.Text, l_nSize)) then
  begin
      Progressbar9.Max := l_nSize div 1000;
      Progressbar10.Max := l_nSize div 1000;
      Progressbar9.Position := (l_nSize div 1000) - (NewWorkingMemory div 1024);
      Progressbar10.Position := ((OldWorkingMemory) div 10000);
  end;
  // end PPROCESS_MEMORY_COUNTERS
  FreeMem(pmc);
end;