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
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
529 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
460 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 ...
5
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:...
1
vote
0answers
93 views

Memory access pattern

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

Implementing realloc in C

I have an assignment to implement realloc in C, This's my code please review it. ...
6
votes
1answer
322 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
851 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
78 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
2k 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
2k 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
207 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
213 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
183 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
740 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 ...
0
votes
2answers
742 views

Memory issues when copying JPEG into bmp

I am trying as a part of a bigger job to merge parts of several JPEGs into one huge BMP which will be processed further. As a start, I tried to just copy a few JPEGs each to his own BMP file. In ...
2
votes
2answers
1k views

Simple class to mimic a dynamic array

for my c++ class I was asked to write a class with the following characteristics: Implement a vector replacement that operates only on integers (you don't need to use templates like the normal STL)...
2
votes
1answer
180 views

Templated double ended queue (deque) move semantics edge cases C++

My original deque implementation and efficiency question lacked move semantics. After ratchet freak provided an example of how to define them I decided to try adding them to my deque. The unit test + ...
4
votes
1answer
503 views

Template double ended queue (deque) implementation using dynamic allocation C++

I have written my own deque class to get a better grasp of C++ pointers and memory management. The following code is part of a larger 2D isometric game I am developing. It compiles and runs fine using ...
7
votes
1answer
1k views

Reference Counting in C99

(I created a GitHub repository; there are few improvements as suggested by other users in the comments) As we know, C99 has no garbage collector. To address the problem of manually deallocate objects ...
1
vote
2answers
2k views

Perlin Noise Generator

I'm porting a 2-D Terrain Generator from Python to C++ as Python is too slow due to the number of features that have been added. I'm new to C++ and would like to know of any criticisms that you can ...
2
votes
1answer
476 views

Dynamic Array Bags

For one of my assignments, we were asked to create a data structure similar to Bags using dynamic arrays where the order would be important - which I was able to do successfully, that is, the code ...
2
votes
1answer
360 views

Basic memory pool, alignment, thread safety

Mainly for practicing purposes, I'm trying to implement a simple, yet efficient memory pool. It's basically a linked list that is able to grow, with fixed sized members. Each node has a flag if it's ...
1
vote
1answer
46 views

Simple but (hopefully) safe C nodes for data structures

Nodes will be for simply linked lists, circular lists, maybe later on extending them to work with graphs. I'm trying to be as defensive as possible, will this leak memory? It runs perfectly I'm just ...
18
votes
3answers
3k views

A vector-like polymorphic container to store objects from a type hierarchy in contiguous memory

Normally, in order to have a polymorphic collection, we store pointers to a base class: ...
4
votes
1answer
482 views

Memory allocation tracking using anonymous lambda wrapper

I had this idea to exploit anonymous lambdas that are immediately executed that wrap around an allocation function to track those allocations in a statically created Stats object. This is the code I ...
2
votes
1answer
1k views

Ensure that ICommand implementation properly uses weak references

I am building an implementation of System.Windows.Input.ICommand that is like the commonly used RelayCommand, but doesn't keep a ...
1
vote
0answers
103 views

Helper class for accessing blobs and mmap memory - follow up

This class was inspired from Microsoft's array_view. It intended to use with mmap-ed memory for easily check bounds and so on. I probably will need to throw exceptions, but this is not my usual way ...
2
votes
1answer
148 views

Helper class for accessing blobs and mmap memory

This class was inspired from Microsoft's array_view. It intended to use with mmap-ed memory for easily check bounds and so on. ...
0
votes
2answers
409 views

Code for calculating number of trailing zeroes after factorial

While trying my hands at the beginner codechef problem I came across this . So basically doing that problem with Dynamic programming is an overkill but why not try that and get some DP practice. Nice,...
6
votes
2answers
311 views

ObservingCache - scheduled task executor that returns a result

I wrote a utility class called ObservingCache, which receives a task in the form of Supplier<T> and an interval, computes the task every [interval] millis and ...
4
votes
2answers
85 views

A dynamic memory resource with alignment support

Although C11 introduced aligned_alloc( alignment, size ), there is no support for aligned reallocation (AFAIK). The ...
4
votes
2answers
773 views

Simple program to read memory usage by PID in Linux

I just learn a little bit about C Programming and try to create a modular program so I created simple program to read memory usage by pid(s) in Linux. ...
1
vote
1answer
2k views

Brute-force password cracker

I am trying to write a program to find a zip file's password. I know the password consists of only lower-case letters and it's length does not exceed 6 characters. I wanted to check the passwords of ...
0
votes
1answer
46 views

Split a file into individually allocated lines

This is part of a larger project that is to run on POSIX systems. My concerns with it are the lack of comments, best practices with the filesystem, and naming things. Of course all feedback is great. ...
3
votes
1answer
71 views

Round-tripping from LinkedHashMaps to Clojure collections

I'm trying to implement round-tripping from LinkedHashMaps to Clojure collections. The implementation below works for smaller collections, but larger collections raise ...
11
votes
3answers
4k views

Structure to ByteArray Extension

I have a need to turn various structures into byte arrays to be sent over serial port to another machine. I created generic extensions to turn any structure into a byte array and from a byte array ...
11
votes
2answers
2k views

Taking arbitrary length input in C

Instead of having to use something like char buf[100500] and hope that no possible user input could be longer than 100500 bytes, I decided to make the following ...
4
votes
0answers
273 views

cross-platform stdlib-only aligned allocator in C++14

I'm writing a program which uses OpenCL, and the OpenCL types are mostly over-aligned. Sometimes when using stl containers with these types, I'd get segfaults, so I tried to write my own aligned ...
5
votes
2answers
179 views

NamedPoint class using unique_ptr for members

After reading this old article from 2001 I have tried to implement the class from it using unique_pointer. An author's claim is that C++ is not appropriate for ...
4
votes
1answer
253 views

New malloc implementation

I've written a new malloc implementation similar to dlmalloc and was hoping for feedback on it. The goals for this library are: ...
0
votes
1answer
174 views

Serial communuication application of 24*7 having memory issue

I am having a serial port communication application using 3 serial ports DMX (m_port,m_port1,m_port2) which will run 24 *7 , so i just need to ensure memory usage doesn't go above limit with using(), ...
8
votes
5answers
7k views

Custom list to avoid out of memory exceptions

The following class is a helper to avoid OutOfMemoryException exceptions being thrown when the list is to large so that it is added onto the large objects heap. To ...