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
4
votes
0answers
177 views

Cleaning up memory after loading Access DB into a datagrid

I wrote an app that pulls a MS Access DB into a DataTable and then displays it into a WPF datagrid. The dialog window has a search button which calls on a class ...
11
votes
4answers
4k views

C++ Doubly Linked List Implementation

Does anyone have suggestions on how to improve this? Specifically: Am I passing and returning references correctly to prevent unnecessary copying? Am I using destructors and the delete keyword ...
0
votes
1answer
2k views

A factory with static objects or an enum with instance objects?

My application accepts different messages. A message is described by its schema. enum ...
5
votes
4answers
279 views

Simple SingleLinkedList Implementation in C++

Below I have a very simple LinkedList implementation. I was wondering if there are any memory leak problems with this and if I used the pointers correctly. I just started practicing with C++ and ...
3
votes
0answers
222 views

Applying Scikit-Learn Linear Kernel with a generator for low memory pressure

matrix = # a sparse matrix of TFIDF vectors - 28458x3218988 My aim was to create a similarity matrix comparing all documents to all documents using ...
2
votes
1answer
87 views

Unsafe collection which allows immutable access while also allowing push()

To get myself used to writing unsafe code, I wrote a collection which allows the user to keep immutable references to the elements of a vector while still being ...
2
votes
3answers
116 views

Project Euler #12 in C (memory management)

I haven't written one bit of C code in well over a decade, being mostly in C#, Rust and Elixir. That being said I have a work reason to work in some C code (much to my dismay) and I'm trying to get ...
3
votes
0answers
346 views

Attempt at multithreaded memory allocator

I'm trying to learn C and memory management, therefore as an exercise I've written a memory allocator. I've taken the best fit algorithm and added multithreading with locks. I'm a beginner with ...
3
votes
0answers
374 views

Populate MongoDB with random documents using a Go channel

I recently created a small app in Go that generates random bson documents and insert them in a database (MongoDB). See this question for details. After doing some profiling, I realised that garbage ...
2
votes
1answer
758 views

Test code for custom malloc

I've been working on a custom malloc where the test code is the following. ...
2
votes
0answers
359 views

Partial file encryption with AES

Task is to encrypt part of the file using aes encryption algorithm. I did ...
2
votes
1answer
283 views

Thread-safe Shared Pointer implementation in C

I've been working on a C project where I needed a small, thread-safe shared pointer, and so I wrote this implementation. It's primary use in the project is as a way of allowing multiple threads to ...
1
vote
1answer
747 views

MemoryError for a small-ish dataset with RandomForestClassifier()

I have a not-so-big dataset having 100,000 rows and 6k columns and I'm using the following code to fit a Random Forest to it: ...
1
vote
2answers
108 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: ...
2
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
121 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
404 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 ...
7
votes
2answers
142 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 ...
8
votes
1answer
2k 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
208 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 ...
14
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 ...
5
votes
2answers
2k views

Fixed size Memory Pool Implementation

Here is an attempt at implementing a fixed size Memory Pool1: pool.h ...
8
votes
2answers
316 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
6k 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
3k views

Implement `Dispose` method in C#

I have a class: ...
6
votes
2answers
2k 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
74 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 ...
4
votes
2answers
287 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
311 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
92 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
549 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
579 views

A simple C++ Trie for working with strings

Here is a simple C++ 11 trie for insertion and membership testing: ...
2
votes
1answer
5k 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
835 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 ...
2
votes
1answer
62 views

Saving User Preferences

I have the following given code after some refactoring: ...
5
votes
1answer
643 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
249 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
362 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
49 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
1k views

My own little memory manager in C

I have implemented a simple version of malloc() and its associated functions, free(), ...
7
votes
2answers
502 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
459 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? ...
3
votes
2answers
4k 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 ...
1
vote
0answers
158 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
143 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 ...
4
votes
2answers
4k 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
177 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:...