Questions tagged [memory-management]

Memory management is the act of managing computer memory by allocating portions of memory to programs as well as freeing memory so that it can be re-used.

Filter by
Sorted by
Tagged with
0
votes
1answer
31 views

Code to write a C template file [closed]

I am writing code to write a C template file; the executable takes two arguments (main) <file name> and ...
3
votes
1answer
80 views

Unique and shared resource owner

I need a unique_ptr and shared_ptr like structure, but instead of pointers, I would like to store some kind of reference to a ...
2
votes
4answers
109 views

I'm deallocating objects created but I'm unsure whether my code is leaking memory or not

I have a simple application which requires the user to input details about students and their grades. I have two different classes Student and ...
4
votes
3answers
106 views

Rotate square matrix clockwise by 90degrees

...
0
votes
3answers
95 views

Safer & simpler allocation functions and macros

I wrote a bunch of functions and macros for safer and simpler allocation. They are documented in their files. Disclaimer: The library requires POSIX extensions, GCC extensions, and LIBBSD ...
1
vote
1answer
48 views

Custom bounded memory pool allocator

Recently I put together a custom fixed size (bounded) memory pool for my job system implementation to support its internal memory management. Since it will be accessed by different threads I want to ...
7
votes
2answers
1k views

Leak detection simple class

Basic idea is to use a Class, with static methods to add and remove references in a static vector, that keeps track of these references, and check that vector upon exit. The class is detecting ...
5
votes
1answer
100 views
11
votes
5answers
3k views

Python's .split() implemented in C

I'm new to the C programming language and I just made a basic version of Python's split() function using C. Note: A major functionality I chose not to implement is ...
2
votes
0answers
28 views

A lightweight version of std::shared_ptr<T> V2

This is a lightweight version of std::shared_ptr<T> called res_ptr<T> This post is a continuation of: A lightweight ...
4
votes
3answers
118 views

Simple shared pointer implementation in a single threaded environment (revised)

std::shared_ptr does not stop you from having the same resource managed by multiple control-blocks (and thus independent sets of shared-pointers), even though it is ...
4
votes
1answer
39 views

simple shared pointer implementation in single threaded environment

Update: The code below has some obvious problems, and it is not allowed to revise code in the original question, so I have to post a new question, the revised code is here. ...
7
votes
2answers
300 views

A lightweight version of std::shared_ptr<T>

I wrote a simple lighter version of std::shared_ptr<T> called res_ptr<T>. ...
5
votes
1answer
35 views

Finding the largest jacobian in a finite element mesh

So I'm trying to implement the following problem in a couple of different languages to get a rough idea of how different languages work & feel. I'm completely new to C, and this is the first code ...
4
votes
1answer
60 views

C Garbage Heap aka simplest memory management tool

The idea is to init garbage heap in the beginning of main, use gmalloc, gcalloc and ...
4
votes
0answers
126 views

Polymorphic deleter for unique_ptr

There is a basic difference in the way C++ manages the deleter for std::unique_ptr and std::shared_ptr, mainly for allowing ...
2
votes
1answer
70 views

Remove duplicates from an unsorted Linked List in Ruby

Currently I'm going over the cracking the coding interview. I'm in the Linked List 2.1 question which is as follow: Remove Duplicates, write code to remove duplicates from an unsorted Linked List....
3
votes
1answer
159 views

Implementing sbrk for a custom allocator in C

I took on a for-fun task of creating a memory allocator which uses process memory rather than making a bunch of system calls to the operating system. The task was: implement my own ...
1
vote
1answer
155 views

Fast insert, fast removal and fast access object pool C++ container

I just want to gather some feedback about this container, in my view it solves the problem of common data containers which don't have fast access and fast deletion. I want to admit that I have not ...
4
votes
2answers
97 views

MVVM model letting the user select a directory in a testable manner

My application needs to let the user select a folder from somewhere on their local machine. Below are the interface and model pair that I have written to let the user do so. ...
10
votes
1answer
285 views

Static block memory allocator

I've found a little task to create a block memory pool allocator. This allocator is required to allocate memory in single fixed-sized blocks from the pool in static memory. Sizes of block and pool are ...
-3
votes
1answer
187 views

Binary tree algorithm for 2D bin packing

I have re-implemented in C++ an algorithm already in JavaScript available here and there. C++ code works fine, but I have memory management concerns: I allocate memory with such statement as ...
4
votes
1answer
54 views

Single-thread Task Scheduler with type erasure and allocator-aware

I made a task scheduler to practice allocators and type erasure. With my project, you can delay execution of any callable (functions (using std::ref), lambdas...) ...
1
vote
0answers
61 views

Managing millions of objects in a MMO game server [closed]

A litle context: This game server is coded entirely on C-with-classes (plain C code using basic C++ features like classes, templates and such, to avoid any possible overhead). At startup the server ...
13
votes
2answers
2k views

Asynchronous Circular Buffer in C#

Preamble I want to be able to test methods which communicate over a simple exclusively asynchronous two-way stream-like interface which may underneath use any of a number of communication methods (e....
1
vote
1answer
67 views

Boolean class using shared referenced memory

To improve my knowledge I am trying to make a bool class from scratch, or derivative of. I am using MinGW g++11 compiler on a Windows 7 laptop. ...
6
votes
2answers
633 views

Safe Dispose of Timer

I am currently refactoring a larger solution where the compiler gave multiple warnings about disposing the used System.Timers.Timer instances. The timers are ...
2
votes
1answer
230 views

Exposing a simple struct using Rust FFI

I am trying to expose a simple struct via FFI. Is this the best way to do it? I am not 100% sure about the get_text function. This is taking the string out of the struct and cloning it before ...
4
votes
3answers
150 views

Fast-resizing uint8 buffer

I wanted a buffer like std::vector<uint8_t> which is very fast at resizing, and it does not require byte initialization (it resizes to 16K, then to 2-4 bytes, ...
2
votes
1answer
120 views

A heap-allocated texture class for a console renderer

I am working on a console renderer and I want a heap-allocated dynamic texture class. Since I am quite new to C++, I just want to check the memory management, if I destroy all pointers correctly etc. ...
0
votes
0answers
54 views

Helper to convert arbitrary function into a custom deleter

If you want to use a custom deleter in unique_ptr you either have to pass a functor or the signature of a delete function as template argument. If you have a ...
4
votes
1answer
70 views

Passing Array into Unmanaged Code for Modification

I have an array allocated in C# which I am passing into unmanaged code to be modified. The following code works, but I am not sure if there are any other more '...
2
votes
1answer
40 views

Force ConcurrentDictionary in a Singleton Registry to Collect Removed Items/Space

I have the following class which is used in a WebApi AspNetCore application as a singleton instance to store Strategy objects (reference type). The class is ...
4
votes
2answers
56 views

Command to measure CPU time and RAM usage of process while making sure it does not go over certain ressource limitation

I found some old code of mine and am trying to see if it can be improved. The goal is to write a command that measures a process's CPU time and RAM peak usage and kills the process if it exceeds a ...
2
votes
0answers
15 views

Thread safe Shareable and Splittable Buffer with Safe Memory (Project)

Backstory This is a buffer I wrote for use in multiple personal projects. It is designed to handle pretty much any data in pretty much any way. In particular I intend to use it in such instances as ...
3
votes
0answers
73 views

Simple and safe C++ pool allocator

I have written a simple pool allocator for C++ and I'm looking for ways to improve it, in speed, usability or safety. For example, I don't know how to allocate a buffer larger than the pool size. <...
8
votes
1answer
180 views

Custom malloc implementation

I have a malloc() implementation that relies purely on mmap. I'm fairly sure that it doesn't overwrite any of the internal ...
3
votes
0answers
113 views

A fixed-size dynamic array

Background I implemented the historic std::dynarray according to the specification under the name dynamic_array in C++17. ...
1
vote
1answer
153 views

Memory policy with ArrayPool<T>.Shared

i've recently released a from scratch set of library Astron, and I wanted to get my memory policy logic reviewed.(you can find a little doc about it here). My first goal was to provide an extandable ...
5
votes
2answers
203 views

A static array implementation in C++

I'm implementing a basic array data structure with basic functionalities. ...
3
votes
1answer
316 views

Implicit Async and none async event handlers

I have implemented a event aggregator for our backend. ...
6
votes
2answers
278 views

Unmanaged byte array to managed structure

I have a need to turn byte arrays into various structures. First version: ...
7
votes
3answers
1k views

malloc in main() or malloc in another function: allocating memory for a struct and its members

When initializing a struct in C, we can allocate memory inside the main function or within another function and return a pointer to the newly created struct. This ...
5
votes
1answer
185 views

A C++17 `std::allocator` implementation

This is an implementation of C++17 std::allocator under the name my_std::allocator, with deprecated stuff omitted for simplicity....
4
votes
0answers
269 views

C++ shared_ptr memory pool

I put together this little memory pool class to help avoid the costs associated with heap allocation and deallocation of objects that are frequently created & destroyed. It creates C++ standard <...
5
votes
1answer
77 views

A custom, highly-specialized, special-purpose standard-compliant C++ allocator

Brief Preface I recognize that there are many nuances and requirements for a standard-compatible allocator. There are a number of questions here covering a range of topics associated with allocators....
2
votes
1answer
54 views

Wipe sensitive information from memory in Python

I have come up with the following method to remove sensitive information with the help of the garbage collector: ...
1
vote
0answers
21 views

Initializing and managing many references in multithreaded control application

I have a large multi-window GUI program (implemented with MFC) that controls a variety of physics experiment apparatus. When the user starts the main function of the program (the "experiment" run), a ...
2
votes
1answer
46 views

Constructor for a packagetarget struct

As many of you know goto is usually signs of code smell. However I thought this could be an appropriate case, and would like confirmation or criticism. Unnecessary ...
2
votes
1answer
56 views

1 2 3 4 5 11