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
29
votes
1answer
3k views

Yet another 'any' class implementation, named 'some'

This is a follow-up of 'any' class implementation. After posting my answer, I kept working on the code towards parameterizing with respect to memory management as I had promised. I ended up in some ...
28
votes
5answers
4k views

C++ Vector Clone

I'm learning C++, so I decided to make a simpler clone of std::vector. Concerns: I have seen people defining methods outside of the class, and only prototyping ...
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 ...
24
votes
1answer
19k views

Efficient smart pointer implementation in C++

The idea behind this is mainly educational but I might even consider using it in reality if turns out to be good. Here's my first try at implementing smart pointers: ...
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. ...
21
votes
1answer
1k views

Tiny Lua library to get char pointer from string

Background I'm using Lua with luaglut to do some OpenGL stuff. The luaglut API is almost identical to the gl/glut C APIs. Sometimes, gl functions want a pointer to some data, for example: ...
21
votes
1answer
491 views

Aligning your heterogenous uninitialized memory to make the processor happy

After learning more about memory alignment and how it can impact processor data access, I tried to find something in the standard that offers proper memory alignment inside blocks of raw memory that ...
17
votes
2answers
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: ...
15
votes
6answers
10k views

Small one time pad encryption program

This one time pad encryption program I have written (basically just an XOR "encryption" program) seems to be working fine, compiling nicely (gcc -o ./OTP.c), and doing what it's supposed to. However I ...
15
votes
1answer
31k views

Alternative to setInterval and setTimeout

JavaScript's setTimeout() and setInterval() are evil and not precise: Both functions have a delay of a varying quantity of ...
14
votes
2answers
16k views

Reading n chars from stream to string

I need to read n chars from a binary file into a string. Currently, what I do is: ...
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 ...
14
votes
2answers
6k views

Fixed-size block allocator

I have written a fixed-size block allocator implementation and would like some feedback as to what I could improve in my code and coding practices. Your comments or notes are welcomed! An auxiliary ...
14
votes
2answers
2k views

Free a binary tree without using recursion or allocating memory

As the title says, the objective is to free a binary tree without using the stack or allocating memory. This was required for a kernel module where resources were limited. Result has a complexity of \...
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 ...
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 ...
13
votes
1answer
1k 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....
12
votes
2answers
1k views

Weapon and Hero classes

For me as a complete newbie to the world of C++, getters and setters are a rather confusing topic. There seems to be a wide range of opinions on what constitutes a sound use of getters and setters. In ...
12
votes
3answers
2k views

Stack implementation with move semantics

I have implemented a basic stack just for fun. I've just started learning about move constructors and assignment and move semantics as a whole, so I would really appreciate some feedback as to whether ...
12
votes
3answers
6k views

Random permutation of int[] and ArrayList<Integer>

I wrote a simple program using int[] and ArrayList<Integer> which aims to get a random permutation output between 1 to 10, ...
12
votes
3answers
1k views

Doubly linked list with no apparent memory leaks

I've run my code through Valgrind and managed to not get any memory leaks based on the test code in main. I'm looking for things that I may not have thought to check for, and ways to improve my code ...
12
votes
4answers
329 views

Bare-bones string library

After years of criticizing others, I've finally found the time and worked up the courage to polish up one of my bits of code and solicit criticisms of my own. This is a simple dynamic-string library ...
12
votes
1answer
3k views

Arena memory allocator

I'm not exactly sure if this is technically an "arena allocator" but it serves a similar purpose: providing a fast way to allocate a lot of objects that can all be freed at once. ...
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 ...
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 ...
11
votes
2answers
4k views

malloc implementation

Please give me some feedback to my malloc implementation. I implemented this design to understand the basic concept. ...
11
votes
4answers
2k views

“Restaurant” HackerRank challenge in C

I don't write C all that often, so things to look for would be memory leaks and such. I also recognize that I'm not validating the user input as well as I could - I could use some feedback on how I ...
11
votes
2answers
1k views

malloc() and free() for Linux with system calls

I have written an implementation of malloc() and free() for Linux using the sbrk() system ...
11
votes
1answer
14k views

malloc(), free(), realloc() using brk() and sbrk()

I recoded malloc() by using brk() and sbrk(). I just want some "reviews" to see if it is ...
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
1k views

Linked list arithmetic

I am practicing for interviews and I tried solving the problem on my own and got a solution. I was wondering how can I improve the performance and memory on this program? The problem performs ...
11
votes
3answers
1k views

Reusing strings read from I/O

I am working on an application that reads lots of data from the network and puts it in a grid. I noticed that I could save some memory by reusing existing strings instead of always using the new ...
11
votes
2answers
1k views

Implementation of a lock-free fixed-sized allocator

This question now has a follow-up: Implementation of a lock-free fixed-sized allocator - follow-up - with commented code I've tried implementing a lock-free fixed-size allocator while trying to ...
11
votes
1answer
91 views

Longest lines using priority queue

Inspired by a comment on this question, I thought I'd exercise my C skills by implementing something like it using a priority queue. The idea is to be able to invoke the program like this: ./...
10
votes
5answers
1k views

Static factory function and lifetime

I'm trying to teach myself C++ at the moment, after years of C# and other managed languages. The class in question is a Level in a game, and the idea is to ...
10
votes
2answers
4k views

Yet another implementation of malloc() in C

I'm really curious to know someone else's opinion on this implementation. Specifically, I would be interested to know the way you would have implemented it. Here the list of issues I've found with in ...
10
votes
2answers
1k views

Image handling class

Let me start by saying that I am very happy with this code. I want to share it with other people because I think they will find it helpful, but I want to make sure I did everything in good form ...
10
votes
3answers
2k views

Checking for palindromes using dynamic memory allocation

This is a homework assignment, but it's already done and it's not for a grade; it's meant as a refresher for the rest of the course. I've never done anything with dynamic memory allocation in C before,...
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(), ...
10
votes
4answers
2k views

Simple key-value store in C, take 2

Followup to Simple key-value store in C. Response to previous reviews You may want to hide the KVSstore structure Done. Add a comparison function pointer to KVSstore. If this pointer is null, ...
10
votes
3answers
703 views

Garbage collection in JavaScript multiplayer game

I am currently creating a Multiplayer Game using node.js and web sockets. The client side is receiving the positional information and applying it to all the players on the client side. Each client ...
10
votes
1answer
1k views

Using the CMA-ES algorithm to optimize the position of wind turbines

I have an implementation of an optimization algorithm called the Covariance Matrix Adaptation Evolutionary Strategy (CMA-ES). I am using this algorithm to optimize the position of wind turbines inside ...
10
votes
1answer
572 views

Pascal Triangle program in C

I've created a program to calculate Pascal's triangle: ...
10
votes
1answer
140 views

Block allocator

I wrote this block allocator for exercise and would love to get your reviews. Main features I wanted to have: Detecting buffer overflows with canary terminator. Being able to allocate arbitrary ...
10
votes
1answer
309 views

Wrapping types with alignment requirements

Visual Studio 2013 still doesn't support the alignas keyword in C++11. This causes some problems with alignment of types in various situations. Thankfully the ...
10
votes
2answers
2k views

C++ custom memory allocator

I'm working on a C++ custom memory allocator, that would be kind of a replacement for the C flexible array syntax, you know, the stuff like that: ...
9
votes
3answers
31k views

Implementing an ArrayList

I implemented ArrayList functionality in C as follows: ...
9
votes
4answers
1k views

Populating a structure

I'm solving K&R exercise 1-13: Write a program to print a histogram of the lengths of words in its input. It is easy to draw the histogram with the bars horizontal; a vertical orientation ...
9
votes
4answers
30k views

Using std::unique_ptr and std::move

I'm trying out new things (on class Inproc), specifically using std::unique_ptr and std::move...
9
votes
3answers
16k views

Copy constructor and assignment operator for doubly linked list

I have implemented a doubly linked list in C++. I have tested it and everything works as expected, but I am not sure if my copy constructor and assignment operator perform a deep copy. Can someone ...