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
1
vote
2answers
115 views

A pointer that stores its size at the front

There are two main ways to keep the size of a pointer. One as just another variable along side: ...
4
votes
1answer
2k views

Apply the smallest possible datatype for each column in a pandas dataframe to reduce RAM use

This function is for Python Pandas users. I noticed a lot of RAM can be saved by applying smaller datatypes to columns. The function's input is a Pandas DataFrame. The function output is the compact ...
3
votes
1answer
124 views

Dynamic Allocation and Reallocation of Memory

This is a code snippet of a larger program. I tried to simplify it as much as possible. This code identifies certain particles and stores them in a list which corresponds to a certain processor. ...
3
votes
1answer
511 views

Allocation and reallocation of memory

I am programming a parallel tree algorithm where I have to send data to other processors. The amount of data is not constant. Therefore I have to work with dynamic arrays using ...
6
votes
2answers
157 views

“Safe” memory management

In order to concisify the handling of a failed call to malloc, realloc, or calloc, I have ...
24
votes
6answers
5k views

C++ string operators

I'm trying to practice my C++ on my own; At the moment I'm trying to implement the concept of operator overloading making my own string class/function. I think I handled this correctly; the code ...
11
votes
1answer
4k views

Resource Manager in C++ for Games

I'm currently writing a small game, needing some advice for things I could do better on this resource management system. Speed is not crucial, and I have no memory budget. The goal is to load and ...
6
votes
1answer
248 views

Code to check for memory leaks

I want to write a header file for c++. When included in a program, the header file overloads the new and delete operators so ...
13
votes
1answer
2k views

C++ class for aligning objects on the stack

I wrote a short class which allocates objects on the stack and aligns them to a specific memory address. Alignment makes sense for some objects (i.e. some SIMD intrinsics require aligned data). I ...
6
votes
2answers
4k views

Fixed size Memory Pool Implementation

Here is an attempt at implementing a fixed size Memory Pool1: pool.h ...
8
votes
2answers
398 views

WeakCollection<T> class

Occasionally I have need for a collection of objects in which each object is referenced "weakly" (meaning the GC is allowed to collect it even when the object is in the collection). Traditionally, I ...
6
votes
2answers
9k views

C++ Trie using std::map and std::unique_ptr

I'm learning C++ and whilst trying to write in modern C++, I've made an attempt to rewrite a trie implementation written in C found here: http://www.geeksforgeeks.org/trie-insert-and-search/ It uses ...
6
votes
3answers
4k views

Implement `Dispose` method in C#

I have a class: ...
6
votes
2answers
3k views

C# to C++ function call that fills and auto resize array if size is not enough

I have a C# function that calls a C++ function to fill the array with pixel data from a camera. This is better than allocating memory on the C++ side and marshaling it on C# side each time the ...
0
votes
1answer
117 views

Python algorithm mimicking mark/sweep garbage collection 2.0

Here I have incorporated the excellent feedback from this question to improve a small program that simulates a Mark/Sweep G.C. Algorithm. The code overall is much cleaner and the functionality is ...
5
votes
2answers
393 views

Python algorithm mimicking mark/sweep garbage collection

I don't have much experience with Python and would love some feedback on my implementation of this program. I am given a file with an integer representing a number of memory-cells, followed by a list ...
1
vote
3answers
375 views

Memory management for matrices built with dynamic arrays

I am working on C++ code which builds matrices (3D and 4D) using dynamic arrays. I am using arrays instead of std::vector; as in the future, I might extend this ...
2
votes
1answer
97 views

Monitoring real-time air waves

I have a program that monitors real-time air waves and demodulates them into useable data. The program runs fine and with very little issues over time. The only thing I am really interested in is ...
3
votes
2answers
771 views

Read numeric data from a text file using C++

I need to read Numeric Data from a text file that looks like this: 2 cell X-cord Y-cord 1 1.1 2.2 2 2.1 2.0 The first line indicates the dimension (...
2
votes
2answers
777 views

A simple C++ Trie for working with strings

Here is a simple C++ 11 trie for insertion and membership testing: ...
2
votes
1answer
6k views

Vector with move constructor and move assignment operator [closed]

Please verify whether the code for a move constructor and a move assignment operator is correct. ...
13
votes
2answers
868 views

Dynamic memory management for a class hierarchy of geometric shapes

The task was to write function that compare areas of two random generated geometric shapes (circle, square, rectangle) using base class with virtual function. Am I doing it right in terms of memory ...
3
votes
1answer
72 views

Saving User Preferences

I have the following given code after some refactoring: ...
6
votes
1answer
904 views

Pin an array in memory and construct a Bitmap using that buffer

I'm using some resources in the code below to pin an array in memory and construct a Bitmap using that buffer. I'm not sure if I'm handling all of the resourced in ...
2
votes
1answer
341 views

Memory management for fetching a list of drive letters on Windows

I'm using the WinAPI GetLogicalDriveStrings() function that requires a LPWSTR and am wondering if there is a safer way to do ...
4
votes
1answer
480 views

Implementing printf to a string by calling vsnprintf twice

I'm experimenting with writing a dynamic string library in C, and I decided to write an implementation of sprintf. In my code, I call vsnprintf with a buffer of 0 ...
1
vote
0answers
50 views

Two priests talking to one another

It's a part of code where two Threads ("priests") talk to each other. One asks and waits for the second to answer - then something happens depending on what has been answered by second thread. I ...
2
votes
1answer
1k views

Vigenere Cipher in C

I'm going through CS50 and one of the problem sets was to implement a vigenere cipher. I have had some previous classroom experience with C before CS50, but still consider myself a beginner. The ...
2
votes
2answers
134 views

First garbage collector

Today I tried to learn how to make a simple garbage collector for a future project, it didn't need to be fast nor complex nor optimal, it just needed to work. After lots of searching and reading, I ...
10
votes
3answers
2k views

My own little memory manager in C

I have implemented a simple version of malloc() and its associated functions, free(), ...
7
votes
2answers
879 views

Fast variable-length stack allocator for vector<> in C++

I wrote a variable-length stack allocator for the vector<> class in C++ 11. In order to be able to allocate size dynamically at runtime I made use of the non-...
2
votes
0answers
464 views

Get process max memory usage while copying large data

I want to check the memory usage of a process before and after I copy a large file or folder, and also, I want to get the maximum memory usage during file operation. Is this a good method? ...
5
votes
2answers
5k views

Safely handling memory allocation across DLL boundaries in Windows

I know that, in Windows, memory must be deallocated in the same module that allocated it. I have 2 DLLs built with different C++ compilers (VS 6 and VS 2015). In the VS 2015 module, I have an ...
2
votes
0answers
171 views

Custom checked_ptr (like std::shared_ptr) for projects without STL

I have written a class to encapsulate pointers for a platform, where the STL is not available. The idea is to have something similar to std::shared_ptr. However, I ...
3
votes
0answers
152 views

A way to automatically reorder struct fields by their sizes in descending order

Using constexpr and preprocessor magic it is possible to cook a struct which have a minimal size between all possible sizes, keeping all the data members properly ...
6
votes
2answers
6k views

Simple C++ object pool

I am studying computer science and just for the sake of practise I thought of implementing an object pool. This is my first implementation, it is simple and works correctly, but I would love any ...
3
votes
1answer
185 views

Writing order and move assignment when following the Rule of Five

I am a C++ newbie, and trying to figure out what the best practices are for writing the "Big Five" member functions, as prescribed by C++11's unofficial "Rule of Five". My class with a raw pointer is:...
1
vote
0answers
97 views

Memory access pattern

Here is the chunk of the code that hogs the maximum time: ...
24
votes
5answers
12k views

Implementing realloc in C

I have an assignment to implement realloc in C, This's my code please review it. ...
6
votes
1answer
411 views

Locating the largest Collatz Sequence with memoization

Inspired by this question I wrote a memoized form of the collatz sequence calculator. The idea was to cache the sequence lengths for as many sequences as possible, from 0 to some value. I managed to (...
9
votes
2answers
925 views

C++ String class

I made a string class to be used as a replacement for std::string. It has all the find functions (find, ...
4
votes
2answers
68 views

Definition of power functions

I needed to write a simple function that could raise a value x to the n'th power. I found out I could write this function in 2 ...
2
votes
1answer
84 views

Gem to interact with a third party API

I am writing a gem for users to interact with a third party api. I want users to have easy and natural access to objects and properties delivered by the JSON payload. The collection of entities ...
13
votes
5answers
3k views

Zero-initializing large dynamically allocated arrays of double

Arrays of double can be zero-initialized with the { 0 } initializer, which works even on systems that have a binary ...
4
votes
2answers
3k views

Rule of five and move semantics for a string class

I have been learning about the rule of five and I tried to implement an example myself. It all works exactly as I'd expect, but I was wondering if I've missed any obvious issues or easier/faster ways ...
1
vote
2answers
264 views

Massive file sorting algorithm

I was trying to sort a massive file of successive chars in C. I did some research and found a few file sorting algorithms that look the same. Their main idea is to read an amount of data to memory, ...
-1
votes
1answer
2k views

Using shared_ptr as class member [closed]

I have already got the answer for my previous question, and I decided to use std::vector<int> instead of int *. I have ...
1
vote
1answer
288 views

Template binary heap with lambda function comparator C++

This heap will be used for A* search pathfinding in my 2D isometric game engine. It uses lambda functions (instead of std::less or ...
6
votes
1answer
213 views

Counting sort implementation in C

I've just implemented counting sort in C and would like to hear your opinions on it. As I'm usually being rather picky when rating other people's code, please go ahead and be picky, too -- I will try ...
6
votes
1answer
1k views

Pool allocator in C

This is an allocator that is used in replace of malloc if you do a lot of rapid, but small allocations on the heap. I wrote this for reducing system calls to improve performance. It works, but I've ...

1 2 3
4
5
11