SlideShare a Scribd company logo
International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056
Volume: 09 Issue: 05 | May 2022 www.irjet.net p-ISSN: 2395-0072
© 2022, IRJET | Impact Factor value: 7.529 | ISO 9001:2008 Certified Journal | Page 2981
Memory Management in Trading Platforms
Pratik Joshi
---------------------------------------------------------------------***---------------------------------------------------------------------
Abstract – With the increasing volatility in the market we
have seen a sharp rise in number of trades occurring in the
market. These platforms are designed to handle huge volume
of trades thanks to the underlying technology. The memory
management forms a base of these highly efficientalgorithms.
The technique in which OS loads programs into memory so
that it can execute several such processes in parallel is a key
functionality of the CPU. This paper will talk about common
techniques used by tradingplatformsformanagingmemoryof
their applications. With high volume there is always a risk of
crashing the application in the middle of a trading day. An
immediate concern in most cases of a memory leak is
unwanted behavior by the application that causesunexpected
crashes, which could lead to damaged relationships with end
users or clients who use the application. Worse yet, if an
attacker were to figure out a way to trigger a memory leak, it
could allow them to perform a denial-of-service attack. As
such, memory leaks represent a combination of performance
and security concerns. It is therefore recommended to keep
memory managementinmindwhile designingtradingsystems
where computation is of essence. Memoryleakscanbe difficult
to avoid, but there are plenty of tools out there that can help.
It’s recommended that you utilize them regardless of which
programming language you prefer. A compromised memory
could lead to denial-of-service or corrupt the data of your
application. Some common techniques will be covered in this
paper using which the application designer can make a better
system.
Key Words:Fragmentation, paging, bufferoverflow,memory
allocation, high frequency trading, in-memory computing.
1. INTRODUCTION
Financial industry heavily uses high-frequency trading in
which the securities are traded on the financial markets
using high-speed rules-based strategies, and numerous
simultaneous trades – with all the decisions driven by
computerized, quantitative models. The computer program
analyzes the market data and trend and computes a buy or
sell trade or perform other financial services. They compute
the data points to predict the market movement and act.
These trades are 10 times faster than time taken by a trader
doing this manually. These techniques prove to be handy
during market instability,marketvolatilityorfinancial crisis.
Because of the time constraint the systems act much quickly
thereby optimizing the use of technology on trading
platforms.
Memory management represents a vital part of secure
application development. Proper memory management is
like good personal hygiene. We are physically healthier
when we practice proper hygiene. Similarly, applications
perform better when memory use is properlyallocated.This
paper demonstrates the risks of poor memory hygiene,
including bufferoverflow,memory leaks,memoryallocation,
and nulling out pointers. By the end of this paper, you will
have a better understanding of why these processes could
create security risks and how to avoid them.
Memory is a collection of data like instructionsforprocessor
or large array of data. During execution of programs CPU
uses memory to hold data, fetches instructions from
memory. To optimize this flow and make the process
efficient in multi programming environment we need to
ensure efficient utilization of memory. In case of high
frequency trading platform where there is huge volume
every millisecond of reading data from memory matters.
1. Overview of Compilers
Compilers for C and C++ parse source code and emit
instructionsfortheCPUtheyaretargeting.Theseinstructions
are commonly called assembly instructions. Since these
instructions are forthe CPU itself, withnointermediatelayer,
they are described as low‑level instructions. Other
programming languages, like C# or Java, have an entire
middle layer between the compiler‑generated instructions
and what is sent to the CPU, which helps prevent mistakes.
These two languages are thought of as higher‑level
programming languages because they do more behind the
scenes to add safety and security to an application.
Conversely, the safety of an application built with C/C++ is
left in the developer’s hands with very few safeguards in
place to prevent potential bad code from executing on the
CPU.
Static and Dynamic Loading:
A loader is used to load a process into the mainmemory.A
static loader would generally load the entire routine into a
fixed address. Dynamicloaderloadsaroutineonlyafterithas
been called.
Swapping:
When a process executes it must have resided in memory.
Swapping is a process responsibleforswappingroutinesinto
main memory from secondary memory. Swapping allows
high number of processes to be run by efficiently using
algorithm and fitting into memory.
International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056
Volume: 09 Issue: 05 | May 2022 www.irjet.net p-ISSN: 2395-0072
© 2022, IRJET | Impact Factor value: 7.529 | ISO 9001:2008 Certified Journal | Page 2982
Memory allocation:
Memory allocation is the process of setting aside sections
called partitions of memory in a program to be used to store
data for a process. It has two techniques, namely static and
dynamic allocation.
Fragmentation:
When the process is loadedandremovedafterexecutionit
leaves behind the memory blocks which cannot be allocated
to the processes due to their smallsize and theblocksremain
unused.
Paging:
Processes are divided into pages. One page of the process
is to be stored in one of the frames in the memory. Paging
technique is used to avoid using the contiguous allocation of
physical memory.
2. Buffer Overflow
A buffer overflow is simply allocating an array of memory
onto the call stack—the data structure where methods and
functions are stored—and then overfilling it with more data
than it was supposed to handle. The extra bytes written to
memory spill over and overwrite adjacent memory, usually
corrupting other stack‑based variables.
Let’s take an example for demonstrating buffer overflow
with a username of 8 bytes and overflow of 2 bytes in severe
cases, a buffer overflow will corrupt the call stack leading to
a massive crash. Even worse, if an attacker has access to the
source code, they could deduce a way to corrupt the call
stack just enough to change the value of a variable that
normal code could not reach, such as changingtheprivileges
of a user to that of an admin.
Per the Open Web Application Security Project (OWASP),
buffer overflow vulnerabilities typically occur in code that:
 Relies on external data to control its behavior
 Depends upon properties of the data that are
enforced outsideof the immediate scopeof the code
Is so complex that a programmer cannot accurately
predict its behavior
Example:
The following code gathers input from the user and writes
the input characters to astack‑basedarray.Thisstack‑based
array is a fixed length buffer and contains a password. When
overfilled, it will corrupt another variable that determines if
the user has admin privileges. Let’sdemonstratehowserious
this can be:
Run the application and enter a word with 8 or more letters.
For instance, enter in 8 characters of just the character '1',
that is '11111111'.
When done typing, hit Enter to completethe input andfinish.
Note that the character for the Enter key is also returned in
the string (which is '/n').
When the application starts, the memory layout of the stack
variables may looklike this(your compilermaybedifferent):
The left column is the memory address, and the right column
is the data in the memory addressinhexadecimalnotation.In
this situation, you can see how the memory address
increments as it goes down. When the compiler creates or
lays out the call stack, it puts the first variables declared at
the bottom with higher memory addresses, and the last
variables declared at the top with lower memory addresses.
Incrementing a pointer moves it from top to bottom (as our
code above does).
When a buffer overflows, data is written from areas starting
in lower memory addresses, spilling over to areas of higher
memory addresses. Notice how in the table there is a two-
byte gap (in a 32‑bit application) between the declaration of
International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056
Volume: 09 Issue: 05 | May 2022 www.irjet.net p-ISSN: 2395-0072
© 2022, IRJET | Impact Factor value: 7.529 | ISO 9001:2008 Certified Journal | Page 2983
the variables. This will vary depending on your compiler.
When the do/while loop writes its first character: *iter = c,
the memory looks like this:
When the do/while has iterated 5 times, it looks like this:
As you can see, if it continuesunchecked, it willoverwritethe
variables higher up in memory:
By the eighth iteration of the loop, the value of is_admin has
been changed, and programflowwillbealtered.Theprogram
output looks like this:
This example shows how to corrupt a variable on the stack,
but this same type of problem can occur for memory
allocated on the heap as well. Though it may be harder to get
variables so close to each other when allocated on the heap,
the app may crash much later than a stack-based overflow,
making it much harder to debug.
The simplest way to avoid buffer overflow issues is to use a
modern programming language. Avoid C unless you have
experience doing so. Even then, you shouldstronglyconsider
switching toC++, which heavily minimizes dependenceonC-
based, stack-based buffers. In general, the more modern the
language, the safer it is. Meaning, it might not expose such
low-level memory management to the programmer.
Memory Leaks
A memory leak occurs when a developer fails to free an
allocated block of memory when no longer needed. An
application littered with memory leaks will eventually
request a memory chunk and fail, because the address space
is fragmented into tiny pieces.
A memory allocation in C++ looks like this:
The leak happens when nothing more is done after the
memory allocation. Pretty hard to spot, isn’t it? Especially
when the programmer forgets about it.
The simple solution looks like this:
When memory is allocated, it looks for a contiguous block of
memory of a certain size. Any leaked memory that is not
freed is unavailable for other memory and is blocked from
being reallocated again. One memory leak may not be
consequential, but if this happens enough, the application
could crash.
Memory Leak Example
Here is a basic memory leak in C
International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056
Volume: 09 Issue: 05 | May 2022 www.irjet.net p-ISSN: 2395-0072
© 2022, IRJET | Impact Factor value: 7.529 | ISO 9001:2008 Certified Journal | Page 2984
In this example, there are 10 allocations of size MAXSIZE.
Every allocation, except for the last, is lost. If no pointer is
pointed to the allocated block, it is unrecoverable during
program execution. A simple fix to this trivial example is to
place the free() call inside of the “for” loop.
3. CONCLUSIONS
In conclusion therefore, it is evident that memory
management is one of the critical responsibilities of the
operating system. Typically, primary memory isvolatileasit
holds the data and programsneededforprocessesto execute
in the CPU while secondary memoryprovideslongterm data
and program storage. The operating system assigns the
responsibility of managing memory to the memory
management unit (MMU). TheOS ensuresthatprogramsand
data are assigned and moved outofmemoryduringprogram
execution through the MMU which residesintheOS’skernel.
When programs want to run in the CPU, processes must be
swapped in and out of main memory. The swapping process
creates holes that have the possibility of impairing the
system’s throughput. That is because swapping may cause
internal or external fragmentation of the main memory. To
improve throughput and minimize the effects of
fragmentation, several memory placement techniques are
used. These include the first fit policy and best fit policy. In
first fit policy, the OS allocates a process to a hole that is first
available so long as it can accommodate the process.
Therefore, the allocation mechanism uses a process’s index
to allocate the process a position in the queue. However, the
best fit policy can easily lead to the creation of many holes,
impairing the efficiency of the OS.
The policy is since main memory is first scanned of all the
holes that have been created and the hole that can fit the
process’s memory requirements is assigned. One of the
algorithms that is used to assign processes memory holes is
the round robin algorithm. These two allocation methods
have been identified to be very efficient. However,forthe OS
to efficiently work it should allocate memory chunks to
running programs. On the other hand,memorymanagement
cannot be complete if virtual memory is not considered.
Virtual memory supports multiprogramming by allowing
several resident programsto runatthesametime. Allocating
memory on the stack is easy to cleanupafterwards,sincethe
compiler does it for you. As the stack unwinds, the memory
is automatically freed. Memory allocated on the heap is
different; it is not automatically freed, and you must do it
manually.
REFERENCES
[1] Breecher, J. Operating systems memory management.
2011. Web.
[2] A GridGain Systems In-Memory Computing WhitePaper
[3] Loepere, K. Mach 3 Kernel Principles. Open Software
Foundation and Carnegie Mellon University, 1992.
Web.RFC4120: The Kerberos Network Authentication
Service (V5) [Applied Cryptography] Second Edition,
Bruce Schneider
[4] Tanenbaum, Andrew, s. and Albert s. Woodhull.
Operating systems design and Implementation. 2006,
Prentice Hall. Web.
BIOGRAPHIES
I have been in Finance and Technologyfor
over 9 years. At MarketAxess, I design
solutions for our leading electronic
trading platform for fixed-income
securities. My team and I manage the
market data and post-trade services for
the global fixed-income markets. We are
responsible to report trades to clearing
houses in timely manner. I work on
making the trading platform that sees on
an average $300 billion monthly volume
efficient and optimized.

More Related Content

PDF
IRJET - Buffer Overflows Attacks & Defense
PPTX
20101017 program analysis_for_security_livshits_lecture03_security
PPTX
Coding Best Practices For Memory Management
PDF
Memory Safety with Delphi - Jim McKeeth - Webinar June 2024
PPTX
Stack-Based Buffer Overflows
PPTX
fjfh mjgkj jkhglkjh jhlkh lhlkkhl kjhjkhjk
DOCX
What
PDF
Chapter 2 program-security
IRJET - Buffer Overflows Attacks & Defense
20101017 program analysis_for_security_livshits_lecture03_security
Coding Best Practices For Memory Management
Memory Safety with Delphi - Jim McKeeth - Webinar June 2024
Stack-Based Buffer Overflows
fjfh mjgkj jkhglkjh jhlkh lhlkkhl kjhjkhjk
What
Chapter 2 program-security

Similar to Memory Management in Trading Platforms (20)

PDF
Buffer overflow attacks
PPTX
Buffer overflow
PPT
Memory management
PPTX
An Introduction of SQL Injection, Buffer Overflow & Wireless Attack
PPT
operationg systemsdocumentmemorymanagement
PPT
OS-unit-3 part -1mxmxmxmmxmxmmxmxmxmxmxmmxmxmmx.ppt
PDF
Buffer overflow attacks
DOCX
Operating system
PDF
OS Memory Management
PPT
Security related security analyst ppt.ppt
PPT
OPERATING SYSTEM IMPORTANT NOTES_UNIT-4.ppt
PPTX
antoanthongtin_Lesson 3- Software Security (1).pptx
PPTX
Memory Management in System Designing.pptx
PPTX
Operating system memory management
PDF
Memory Management(MM) in operating system
PPT
7. Memory management in operating system.ppt
PDF
Presentation buffer overflow attacks and theircountermeasures
PPT
chap.4.memory.manag.ppt
PPT
4 (1)
PPTX
Control hijacking
Buffer overflow attacks
Buffer overflow
Memory management
An Introduction of SQL Injection, Buffer Overflow & Wireless Attack
operationg systemsdocumentmemorymanagement
OS-unit-3 part -1mxmxmxmmxmxmmxmxmxmxmxmmxmxmmx.ppt
Buffer overflow attacks
Operating system
OS Memory Management
Security related security analyst ppt.ppt
OPERATING SYSTEM IMPORTANT NOTES_UNIT-4.ppt
antoanthongtin_Lesson 3- Software Security (1).pptx
Memory Management in System Designing.pptx
Operating system memory management
Memory Management(MM) in operating system
7. Memory management in operating system.ppt
Presentation buffer overflow attacks and theircountermeasures
chap.4.memory.manag.ppt
4 (1)
Control hijacking

More from IRJET Journal (20)

PDF
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
PDF
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
PDF
Kiona – A Smart Society Automation Project
PDF
DESIGN AND DEVELOPMENT OF BATTERY THERMAL MANAGEMENT SYSTEM USING PHASE CHANG...
PDF
Invest in Innovation: Empowering Ideas through Blockchain Based Crowdfunding
PDF
SPACE WATCH YOUR REAL-TIME SPACE INFORMATION HUB
PDF
A Review on Influence of Fluid Viscous Damper on The Behaviour of Multi-store...
PDF
Wireless Arduino Control via Mobile: Eliminating the Need for a Dedicated Wir...
PDF
Explainable AI(XAI) using LIME and Disease Detection in Mango Leaf by Transfe...
PDF
BRAIN TUMOUR DETECTION AND CLASSIFICATION
PDF
The Project Manager as an ambassador of the contract. The case of NEC4 ECC co...
PDF
"Enhanced Heat Transfer Performance in Shell and Tube Heat Exchangers: A CFD ...
PDF
Advancements in CFD Analysis of Shell and Tube Heat Exchangers with Nanofluid...
PDF
Breast Cancer Detection using Computer Vision
PDF
Auto-Charging E-Vehicle with its battery Management.
PDF
Analysis of high energy charge particle in the Heliosphere
PDF
A Novel System for Recommending Agricultural Crops Using Machine Learning App...
PDF
Auto-Charging E-Vehicle with its battery Management.
PDF
Analysis of high energy charge particle in the Heliosphere
PDF
Wireless Arduino Control via Mobile: Eliminating the Need for a Dedicated Wir...
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
Kiona – A Smart Society Automation Project
DESIGN AND DEVELOPMENT OF BATTERY THERMAL MANAGEMENT SYSTEM USING PHASE CHANG...
Invest in Innovation: Empowering Ideas through Blockchain Based Crowdfunding
SPACE WATCH YOUR REAL-TIME SPACE INFORMATION HUB
A Review on Influence of Fluid Viscous Damper on The Behaviour of Multi-store...
Wireless Arduino Control via Mobile: Eliminating the Need for a Dedicated Wir...
Explainable AI(XAI) using LIME and Disease Detection in Mango Leaf by Transfe...
BRAIN TUMOUR DETECTION AND CLASSIFICATION
The Project Manager as an ambassador of the contract. The case of NEC4 ECC co...
"Enhanced Heat Transfer Performance in Shell and Tube Heat Exchangers: A CFD ...
Advancements in CFD Analysis of Shell and Tube Heat Exchangers with Nanofluid...
Breast Cancer Detection using Computer Vision
Auto-Charging E-Vehicle with its battery Management.
Analysis of high energy charge particle in the Heliosphere
A Novel System for Recommending Agricultural Crops Using Machine Learning App...
Auto-Charging E-Vehicle with its battery Management.
Analysis of high energy charge particle in the Heliosphere
Wireless Arduino Control via Mobile: Eliminating the Need for a Dedicated Wir...

Recently uploaded (20)

PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
web development for engineering and engineering
PPTX
Artificial Intelligence
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
DOCX
573137875-Attendance-Management-System-original
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
Well-logging-methods_new................
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPT
Project quality management in manufacturing
PDF
PPT on Performance Review to get promotions
PPTX
Geodesy 1.pptx...............................................
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
UNIT 4 Total Quality Management .pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
Safety Seminar civil to be ensured for safe working.
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
R24 SURVEYING LAB MANUAL for civil enggi
web development for engineering and engineering
Artificial Intelligence
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
573137875-Attendance-Management-System-original
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Well-logging-methods_new................
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Project quality management in manufacturing
PPT on Performance Review to get promotions
Geodesy 1.pptx...............................................
OOP with Java - Java Introduction (Basics)
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
UNIT 4 Total Quality Management .pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Foundation to blockchain - A guide to Blockchain Tech
Model Code of Practice - Construction Work - 21102022 .pdf
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Safety Seminar civil to be ensured for safe working.

Memory Management in Trading Platforms

  • 1. International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056 Volume: 09 Issue: 05 | May 2022 www.irjet.net p-ISSN: 2395-0072 © 2022, IRJET | Impact Factor value: 7.529 | ISO 9001:2008 Certified Journal | Page 2981 Memory Management in Trading Platforms Pratik Joshi ---------------------------------------------------------------------***--------------------------------------------------------------------- Abstract – With the increasing volatility in the market we have seen a sharp rise in number of trades occurring in the market. These platforms are designed to handle huge volume of trades thanks to the underlying technology. The memory management forms a base of these highly efficientalgorithms. The technique in which OS loads programs into memory so that it can execute several such processes in parallel is a key functionality of the CPU. This paper will talk about common techniques used by tradingplatformsformanagingmemoryof their applications. With high volume there is always a risk of crashing the application in the middle of a trading day. An immediate concern in most cases of a memory leak is unwanted behavior by the application that causesunexpected crashes, which could lead to damaged relationships with end users or clients who use the application. Worse yet, if an attacker were to figure out a way to trigger a memory leak, it could allow them to perform a denial-of-service attack. As such, memory leaks represent a combination of performance and security concerns. It is therefore recommended to keep memory managementinmindwhile designingtradingsystems where computation is of essence. Memoryleakscanbe difficult to avoid, but there are plenty of tools out there that can help. It’s recommended that you utilize them regardless of which programming language you prefer. A compromised memory could lead to denial-of-service or corrupt the data of your application. Some common techniques will be covered in this paper using which the application designer can make a better system. Key Words:Fragmentation, paging, bufferoverflow,memory allocation, high frequency trading, in-memory computing. 1. INTRODUCTION Financial industry heavily uses high-frequency trading in which the securities are traded on the financial markets using high-speed rules-based strategies, and numerous simultaneous trades – with all the decisions driven by computerized, quantitative models. The computer program analyzes the market data and trend and computes a buy or sell trade or perform other financial services. They compute the data points to predict the market movement and act. These trades are 10 times faster than time taken by a trader doing this manually. These techniques prove to be handy during market instability,marketvolatilityorfinancial crisis. Because of the time constraint the systems act much quickly thereby optimizing the use of technology on trading platforms. Memory management represents a vital part of secure application development. Proper memory management is like good personal hygiene. We are physically healthier when we practice proper hygiene. Similarly, applications perform better when memory use is properlyallocated.This paper demonstrates the risks of poor memory hygiene, including bufferoverflow,memory leaks,memoryallocation, and nulling out pointers. By the end of this paper, you will have a better understanding of why these processes could create security risks and how to avoid them. Memory is a collection of data like instructionsforprocessor or large array of data. During execution of programs CPU uses memory to hold data, fetches instructions from memory. To optimize this flow and make the process efficient in multi programming environment we need to ensure efficient utilization of memory. In case of high frequency trading platform where there is huge volume every millisecond of reading data from memory matters. 1. Overview of Compilers Compilers for C and C++ parse source code and emit instructionsfortheCPUtheyaretargeting.Theseinstructions are commonly called assembly instructions. Since these instructions are forthe CPU itself, withnointermediatelayer, they are described as low‑level instructions. Other programming languages, like C# or Java, have an entire middle layer between the compiler‑generated instructions and what is sent to the CPU, which helps prevent mistakes. These two languages are thought of as higher‑level programming languages because they do more behind the scenes to add safety and security to an application. Conversely, the safety of an application built with C/C++ is left in the developer’s hands with very few safeguards in place to prevent potential bad code from executing on the CPU. Static and Dynamic Loading: A loader is used to load a process into the mainmemory.A static loader would generally load the entire routine into a fixed address. Dynamicloaderloadsaroutineonlyafterithas been called. Swapping: When a process executes it must have resided in memory. Swapping is a process responsibleforswappingroutinesinto main memory from secondary memory. Swapping allows high number of processes to be run by efficiently using algorithm and fitting into memory.
  • 2. International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056 Volume: 09 Issue: 05 | May 2022 www.irjet.net p-ISSN: 2395-0072 © 2022, IRJET | Impact Factor value: 7.529 | ISO 9001:2008 Certified Journal | Page 2982 Memory allocation: Memory allocation is the process of setting aside sections called partitions of memory in a program to be used to store data for a process. It has two techniques, namely static and dynamic allocation. Fragmentation: When the process is loadedandremovedafterexecutionit leaves behind the memory blocks which cannot be allocated to the processes due to their smallsize and theblocksremain unused. Paging: Processes are divided into pages. One page of the process is to be stored in one of the frames in the memory. Paging technique is used to avoid using the contiguous allocation of physical memory. 2. Buffer Overflow A buffer overflow is simply allocating an array of memory onto the call stack—the data structure where methods and functions are stored—and then overfilling it with more data than it was supposed to handle. The extra bytes written to memory spill over and overwrite adjacent memory, usually corrupting other stack‑based variables. Let’s take an example for demonstrating buffer overflow with a username of 8 bytes and overflow of 2 bytes in severe cases, a buffer overflow will corrupt the call stack leading to a massive crash. Even worse, if an attacker has access to the source code, they could deduce a way to corrupt the call stack just enough to change the value of a variable that normal code could not reach, such as changingtheprivileges of a user to that of an admin. Per the Open Web Application Security Project (OWASP), buffer overflow vulnerabilities typically occur in code that:  Relies on external data to control its behavior  Depends upon properties of the data that are enforced outsideof the immediate scopeof the code Is so complex that a programmer cannot accurately predict its behavior Example: The following code gathers input from the user and writes the input characters to astack‑basedarray.Thisstack‑based array is a fixed length buffer and contains a password. When overfilled, it will corrupt another variable that determines if the user has admin privileges. Let’sdemonstratehowserious this can be: Run the application and enter a word with 8 or more letters. For instance, enter in 8 characters of just the character '1', that is '11111111'. When done typing, hit Enter to completethe input andfinish. Note that the character for the Enter key is also returned in the string (which is '/n'). When the application starts, the memory layout of the stack variables may looklike this(your compilermaybedifferent): The left column is the memory address, and the right column is the data in the memory addressinhexadecimalnotation.In this situation, you can see how the memory address increments as it goes down. When the compiler creates or lays out the call stack, it puts the first variables declared at the bottom with higher memory addresses, and the last variables declared at the top with lower memory addresses. Incrementing a pointer moves it from top to bottom (as our code above does). When a buffer overflows, data is written from areas starting in lower memory addresses, spilling over to areas of higher memory addresses. Notice how in the table there is a two- byte gap (in a 32‑bit application) between the declaration of
  • 3. International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056 Volume: 09 Issue: 05 | May 2022 www.irjet.net p-ISSN: 2395-0072 © 2022, IRJET | Impact Factor value: 7.529 | ISO 9001:2008 Certified Journal | Page 2983 the variables. This will vary depending on your compiler. When the do/while loop writes its first character: *iter = c, the memory looks like this: When the do/while has iterated 5 times, it looks like this: As you can see, if it continuesunchecked, it willoverwritethe variables higher up in memory: By the eighth iteration of the loop, the value of is_admin has been changed, and programflowwillbealtered.Theprogram output looks like this: This example shows how to corrupt a variable on the stack, but this same type of problem can occur for memory allocated on the heap as well. Though it may be harder to get variables so close to each other when allocated on the heap, the app may crash much later than a stack-based overflow, making it much harder to debug. The simplest way to avoid buffer overflow issues is to use a modern programming language. Avoid C unless you have experience doing so. Even then, you shouldstronglyconsider switching toC++, which heavily minimizes dependenceonC- based, stack-based buffers. In general, the more modern the language, the safer it is. Meaning, it might not expose such low-level memory management to the programmer. Memory Leaks A memory leak occurs when a developer fails to free an allocated block of memory when no longer needed. An application littered with memory leaks will eventually request a memory chunk and fail, because the address space is fragmented into tiny pieces. A memory allocation in C++ looks like this: The leak happens when nothing more is done after the memory allocation. Pretty hard to spot, isn’t it? Especially when the programmer forgets about it. The simple solution looks like this: When memory is allocated, it looks for a contiguous block of memory of a certain size. Any leaked memory that is not freed is unavailable for other memory and is blocked from being reallocated again. One memory leak may not be consequential, but if this happens enough, the application could crash. Memory Leak Example Here is a basic memory leak in C
  • 4. International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056 Volume: 09 Issue: 05 | May 2022 www.irjet.net p-ISSN: 2395-0072 © 2022, IRJET | Impact Factor value: 7.529 | ISO 9001:2008 Certified Journal | Page 2984 In this example, there are 10 allocations of size MAXSIZE. Every allocation, except for the last, is lost. If no pointer is pointed to the allocated block, it is unrecoverable during program execution. A simple fix to this trivial example is to place the free() call inside of the “for” loop. 3. CONCLUSIONS In conclusion therefore, it is evident that memory management is one of the critical responsibilities of the operating system. Typically, primary memory isvolatileasit holds the data and programsneededforprocessesto execute in the CPU while secondary memoryprovideslongterm data and program storage. The operating system assigns the responsibility of managing memory to the memory management unit (MMU). TheOS ensuresthatprogramsand data are assigned and moved outofmemoryduringprogram execution through the MMU which residesintheOS’skernel. When programs want to run in the CPU, processes must be swapped in and out of main memory. The swapping process creates holes that have the possibility of impairing the system’s throughput. That is because swapping may cause internal or external fragmentation of the main memory. To improve throughput and minimize the effects of fragmentation, several memory placement techniques are used. These include the first fit policy and best fit policy. In first fit policy, the OS allocates a process to a hole that is first available so long as it can accommodate the process. Therefore, the allocation mechanism uses a process’s index to allocate the process a position in the queue. However, the best fit policy can easily lead to the creation of many holes, impairing the efficiency of the OS. The policy is since main memory is first scanned of all the holes that have been created and the hole that can fit the process’s memory requirements is assigned. One of the algorithms that is used to assign processes memory holes is the round robin algorithm. These two allocation methods have been identified to be very efficient. However,forthe OS to efficiently work it should allocate memory chunks to running programs. On the other hand,memorymanagement cannot be complete if virtual memory is not considered. Virtual memory supports multiprogramming by allowing several resident programsto runatthesametime. Allocating memory on the stack is easy to cleanupafterwards,sincethe compiler does it for you. As the stack unwinds, the memory is automatically freed. Memory allocated on the heap is different; it is not automatically freed, and you must do it manually. REFERENCES [1] Breecher, J. Operating systems memory management. 2011. Web. [2] A GridGain Systems In-Memory Computing WhitePaper [3] Loepere, K. Mach 3 Kernel Principles. Open Software Foundation and Carnegie Mellon University, 1992. Web.RFC4120: The Kerberos Network Authentication Service (V5) [Applied Cryptography] Second Edition, Bruce Schneider [4] Tanenbaum, Andrew, s. and Albert s. Woodhull. Operating systems design and Implementation. 2006, Prentice Hall. Web. BIOGRAPHIES I have been in Finance and Technologyfor over 9 years. At MarketAxess, I design solutions for our leading electronic trading platform for fixed-income securities. My team and I manage the market data and post-trade services for the global fixed-income markets. We are responsible to report trades to clearing houses in timely manner. I work on making the trading platform that sees on an average $300 billion monthly volume efficient and optimized.