Skip to main content

All Questions

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

Count the number of objects created statically and dynamically in C++

I have written below program to count the number of static and dynamically created object of the class. ...
Naveen Gupta's user avatar
6 votes
1 answer
342 views

Safe new/delete

A student was having problems with memory management so I put together an overload of global operator new and global ...
Aykhan Hagverdili's user avatar
8 votes
2 answers
1k 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 ...
Amir Kirsh's user avatar
1 vote
1 answer
132 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. ...
Danilo's user avatar
  • 195
5 votes
1 answer
1k 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 <...
Thomas Johnson's user avatar
2 votes
0 answers
324 views

Yet Another Non-Intrusive Reference Counted Smart Pointer Implementation

I needed a reference counted smart pointer for my project, and for some reason early in my project, I decided that I did not like the std::shared_ptr. I can't ...
Super Cyb0rg's user avatar
28 votes
5 answers
5k 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 ...
internet_user's user avatar
9 votes
2 answers
6k views

Fast pool allocator for games in C++

I have implemented the following pool allocator in C++: ...
Peter Lenkefi's user avatar
3 votes
0 answers
320 views

C++ object pool using C memory pool as base

I started out with this question on Stack Overflow. I have since then gotten an official answer from the mbed developers that the MemoryPool that I was asking about only issued raw C malloc/free type ...
paulluap's user avatar
2 votes
1 answer
517 views

C++ Policy-based object pool

Description This is an improved implementation for a previous post My goal was to implement a decent object pool using templates and policy based design. The object pool behaviour can be customized ...
amc176's user avatar
  • 345
13 votes
1 answer
3k 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 ...
cruppstahl's user avatar
6 votes
2 answers
16k 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 ...
Cyniscus's user avatar
2 votes
2 answers
992 views

A simple C++ Trie for working with strings

Here is a simple C++ 11 trie for insertion and membership testing: ...
Marcus Handley's user avatar
2 votes
1 answer
9k 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. ...
ankit srivastava's user avatar
13 votes
2 answers
922 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 ...
Paweł Dymowski's user avatar
7 votes
2 answers
9k 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 ...
amc176's user avatar
  • 345
3 votes
1 answer
206 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:...
Daniel's user avatar
  • 131
-1 votes
1 answer
4k 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 ...
AnatoliySultanov's user avatar
2 votes
1 answer
190 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. ...
Nick's user avatar
  • 1,594
5 votes
2 answers
237 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 ...
shtkuh's user avatar
  • 165
2 votes
1 answer
242 views

Pointer lists for a C++ garbage collector

The problem My intention is to have a class A and class B. class B has a ...
peterh's user avatar
  • 237
5 votes
1 answer
617 views

Lazy String splitter in C++

I created a string splitter in C++. It splits a string in a lazy fashion and makes use of forward iterators to sequentially supply the next token from the string until it runs out of tokens. ...
smac89's user avatar
  • 1,499
4 votes
2 answers
2k views

Binary file validity in C++/C++11: checking a binary header

I have some code for checking a binary header to see if a binary file is meant to be read by a certain program, and I could use some extra eyes to review it. Assume the following ...
Dennis's user avatar
  • 43
5 votes
2 answers
197 views

Does my Linklist implementation have memory leaks?

Are there any memory leaks in this linklist implementation.Also is the implementation correct?Can the time complexity be optimized? ...
CodeMaxx's user avatar
  • 127
12 votes
3 answers
3k 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 ...
Ivaylo Valchev's user avatar
2 votes
0 answers
432 views

Implementation of a lock-free fixed-sized allocator - follow-up - with commented code

The following implementation of a lock-free fixed-size allocator is a follow-up of: Implementation of a lock-free fixed-sized allocator §1 - Introduction The purpose is self-learning of atomic ...
cr_oag's user avatar
  • 565
12 votes
2 answers
2k 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 ...
cr_oag's user avatar
  • 565
2 votes
0 answers
88 views

Platform independent leak/cyclic dependency detection of objects

Sometime back I came across a bug where a particular object was leaking but it was very hard to identify the root cause. I knew that it was due to a cyclic dependency (which usually indicates a bug in ...
bashrc's user avatar
  • 121
4 votes
2 answers
122 views

MallocRaii implementation

I'm playing around with RAII a bit lately and I wan't to know if/how I can improve this (quite simple but very helpful) class. A word to two decisions I've made and why: No error handling in ...
tkausl's user avatar
  • 613
6 votes
1 answer
259 views

Pool allocator for a scripting language parser

At the moment I'm writing a parser and interpreter for a custom scripting language, to learn more about the basic concepts involved and to get more familiar with tools like ...
glampert's user avatar
  • 17.2k
6 votes
1 answer
2k views

Applying the copy-swap idiom to humans and employees

I came across this post which explains the copy and swap idiom. However I could not find this idiom applied to classes that have base classes. Following is my attempt of a copy-swap idiom applied to ...
James Franco's user avatar
10 votes
2 answers
3k 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: ...
Aleksey Demakov's user avatar
6 votes
1 answer
28k views

Reading from a CSV file in C++

I wrote this code to read from a CSV text file (containing data such as 12,3,568,48,3,8 with no more than 3 digits to each number). It stores the numbers as char arrays in the vector ...
Robin Hartland's user avatar
8 votes
1 answer
1k views

Rotating and printing an image

I carefully used smart pointer to avoid memory leaks and dangling pointers, but someone says my code has memory leaks. Is it true? If so, how can I fix it? ...
MORTAL's user avatar
  • 3,290
5 votes
2 answers
1k views

Rotate an image (2D array) by 90 degrees recursively with low memory usage

I'm looking for comments on coding style, passing arguments, ...etc. ...
tgaaly's user avatar
  • 149
1 vote
2 answers
25k views

std::vector of pointers with the rule of three

I have a class that has a std::vector of pointers, I'm NOT going to give any of those pointers to objects outside of it, I mean, I'm not going to share the pointers....
yayuj's user avatar
  • 185
11 votes
1 answer
382 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 ...
Emily L.'s user avatar
  • 16.6k
3 votes
1 answer
2k views

Program that handles program options

I'm using boost::program_options to parse input from the user. However, while the standard library makes this an easy task to do, it's causing an (in my opinion) ...
user53899's user avatar
5 votes
2 answers
675 views

Singleton typed memory manager

For my resources management, I wanted the objects allocated on the heap to be in a contiguous block of memory. Obviously, each data type then has to have their own chunk of memory. I could have used a ...
rashmatash's user avatar
3 votes
1 answer
1k views

Auto-recycling C++11 polymorphic smart pointers

I've recently read an interesting blog post by Philipp Zschoche: it explains how it's possible to avoid unnecessary allocations/deallocations by keeping track of previously allocated memory in a stack....
Vittorio Romeo's user avatar
8 votes
1 answer
301 views

Associative container that produces a unique, instance specific handle for each inserted object

It is not always possible to simplify program design by strictly managing the lifetimes of objects. If two objects have unpredictable lifetimes, but one of them needs to refer to the other, a simple ...
jms's user avatar
  • 495
5 votes
2 answers
802 views

Handle-based entity manager (that stores entities contiguously)

I've created a generic data structure intended for game development entity management. It has some interesting properties: Entities are stored contiguously in an ...
Vittorio Romeo's user avatar
31 votes
1 answer
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 ...
iavr's user avatar
  • 2,294
8 votes
1 answer
2k views

Smart pointer memory pool

I'm using a third-party library which utilizes boost::shared_ptr for memory management. The problem is that I need to allocate many objects and I have detected ...
dalle's user avatar
  • 233
8 votes
1 answer
1k views

D3D9 leaks if any?

I am writing a D3D9 hook plugin to give back to a community that helped me learn programming. It is a community based on programming and scripting for games. The plugin is supposed to hook d3d9.dll ...
Brandon's user avatar
  • 183
6 votes
1 answer
5k views

WinAPI code for DNS queries

This is just some test code I'm doing to learn C++11. It compiles and runs consistently. But is anything wrong that will eventually (or under slightly different circumstances) fail? Besides ...
Jason Kleban's user avatar
4 votes
1 answer
2k views

Implementing `create` and `destroy` functions to replace `new` and `delete` operators

The environment I'm working in requires that all allocation is done through a special set of malloc/calloc functions and that a ...
Allan's user avatar
  • 141
4 votes
1 answer
5k views

Memory Pool and Block Alignment

I have written a memory pool (pool_allocator) that was described in a book I am reading (Game Engine Architecture). The interface is pretty basic: The constructor:...
tecu's user avatar
  • 178
11 votes
1 answer
13k views

A working stack allocator

Here's an absolutely essential piece of C++ lore, a stack allocator, that will allow you to, say, allocate strings and vectors on the stack. There are 2 stack allocators I know of, here and here. The ...
user1095108's user avatar
  • 1,434
2 votes
1 answer
3k views

Heap memory preallocation (intended for games)

Currently, in my games, I'm using new and delete to create entities and components. It works fine, but there are slowdowns when ...
Vittorio Romeo's user avatar