Posts

Showing posts from November, 2016

Memory allocation in a Delphi Application

Memory in a Delphi Application When we run our Delphi Application it acquires some memory to store variables, constants, parameters that we have used. And during runtime several  times we create and free objects in our application so accordingly memory is occupied and freed. And those freed memories can be used to store other  values.  So how those memories are managed by a Delphi application, we will see in this blog.  So at first what memory is? in short, computer memories are row of bytes.  One could also say a byte is the smallest addressable piece of memory.  A byte is a small storage unit that can contain 256 separate values (0 up to 255).  In current 32 bit Delphi, memory can be seen as an array of maximum 2 gigabytes in size (231 bytes).  The index of a byte in this huge array is called its address.  What these bytes contain, depends on how they are used like t he value of 97 can mean a byte of value 97, as well as the charact...

Pointers In Delphi

Every data we use in an application is stored somewhere in the computer's memory. And a Pointer is a variable that stores a address of memory piece  where we store data, like in Delphi "a string is really just a pointer" or "an object is really just a pointer" or "event  handler such as OnClick is actually a pointer to a procedure". They allow direct access to memory, enabling complex data structures to be built and navigated. The advantages are: We can set that memory size as per our requirement In case of copy value of a variable from one to another we just need to change a pointer to point to a different address of memory which saved lots of time When we use Pointers The most common use for pointers in Delphi is when calling Windows APIs. Windows API functions use a number of data types that may be unfamiliar to the Delphi programmer. Most of the parameters in calling API functions are pointers to some data type.  Most of the t...