Questions tagged [pointers]

In computer science, a pointer is a programming language data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memory using its address.

Filter by
Sorted by
Tagged with
27
votes
1answer
20k 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: ...
25
votes
5answers
2k views

Inventorizing the universe

I recently started re-factoring a project I hadn't touched in many months. The original purpose was to be an inventory management system for a game I played, Ogame. In this game you play inside a ...
19
votes
3answers
9k views

scoped_ptr for C++/CLI (ensure managed object properly frees owned native object)

Motivating SO question: Is there a C++/CLI smart pointer project (e.g. scoped_ptr)? I'm interested in any reviewer comments, and especially identified bugs or inconsistencies with the native ...
17
votes
2answers
3k views

boost::any replacement with std::unique_ptr support

I needed a boost.any look-a-like, that could handle a std::unique_ptr. I came up with this. Please provide some C++11 criticism. ...
15
votes
4answers
26k views

Implementation of stack using pointers

Please review my code and let me know how I can possibly improve it. ...
15
votes
2answers
1k views

C++11 smart pointer 'library'

Edit: NOTE I'm a C++ "beginner" still in undergrad trying to teach myself modern C++ (because they don't do that in uni) so I'm sure this is riddled with errors that I am unaware of. Made a subset of ...
15
votes
2answers
1k views

Can I buff up your file?

Here I have a method for reading the contents of a file into a buffer and returning whether or not it is successful. Here is what I would like reviewed: Speed: Am I reading in the file as fast as ...
15
votes
1answer
916 views

value_ptr<T> - a C++11 header-only, deep-copying smart pointer that preserves value semantics for polymorphic and undefined types

== UPDATED: next revision HERE == My previous two iterations were here and here. I've since finalized the concept as described in the title, and would appreciate any feedback on the new solution ...
14
votes
3answers
3k views

Hunt the Wumpus

I've made an iteration of the text game Hunt The Wumpus. The specification came from the text Programming Principles and Practice Using C++ by Bjarne Stroustrup. Implement a version of the game "...
14
votes
2answers
79k views

Coding and printing a graph

This is my first attempt at putting the conceptual knowledge I've gained about graphs into code. When searching for examples they all seem overly complicated, and searching for a tutorial or ...
12
votes
3answers
13k views

Tail implementation in C

Write the program tail, which prints the last n lines of its input. By default, n is 10, let ...
12
votes
2answers
595 views

Learning pointers by implementing a basic linked list with tests

I wanted to learn about pointers and someone suggested that I give C a try, so I went through Linked List Basics from Stanford CS library, implemented some of the code (and tried to improve the code a ...
12
votes
3answers
1k views

A moveable QScopedPointer, or a Qt and std cross-compatible unique_pointer

I'm a hobby programmer, so I've never been through a code review before (online or offline). That said, here goes: Background I use Qt extensively but have long wanted ...
12
votes
1answer
6k 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 ...
11
votes
4answers
66k views

Printing the contents of a string array using pointers

I'm currently studying C and I'm trying to just print the contents of a string array. I'm using pNames to point to the first char pointer and iterating from there. ...
11
votes
4answers
7k views

strstr() implementation

In this strstr implementation, I am basically skipping the already matched and checked characters with an if else condition. Is ...
11
votes
2answers
696 views

Beep-beep I'm a car factory

I have implemented to following generic factory in C++11 using smart pointers and I would like to get some feedback about it. (Please note that I can't use C++14) Due to company policies I have to ...
11
votes
2answers
3k views

C struct or pointer to struct?

I am currently using this code (and more) to deal with 2D matrices. I am not very proficient in C, so I am not quite sure, if this is a good way of doing it. I've seen other people in similar ...
11
votes
2answers
1k views

make_auto implementation for C++03 compilers

I want to provide, in the the spirit of C++11/boost make_shared and C++14 make_unique, a production-ready make_auto for C++03 compilers. So, inspired boost's make_shared implementation for C++03 ...
11
votes
1answer
559 views

An optional_ref<T>

I omitted all free operators but the equality comparisons ones because of verbosity. I am glad about any comments and improvements. Motivation I know that optional references are equivalent to ...
10
votes
3answers
3k views

Implementing a Stack with Templates and Smart pointers

I'm trying to understand the concepts of smart pointers and templates. To get a better understanding of these, I tried to implement these two concepts on Stack. I ...
10
votes
5answers
2k views

Custom class for a borrowed unique_ptr<T>?

In C++11, I tend to have master objects that maintain sole ownership of a collection of some children objects. Let's assume these children objects are non-copyable (for instance, ...
10
votes
4answers
14k views

Pointer version of strcat

Write a pointer version of the function strcat that we showed in Chapter 2: strcat(s, t) copies the string t to the end of ...
10
votes
2answers
791 views

C - Learning Linked Lists, Pointer Manipulation - Store some ints, print and free memory

I'm learning C, and wrote this program outside of my assignments in order to practice pointer manipulation and data structures, step by step. I want to ensure that this program follows well known ...
10
votes
2answers
781 views

Smart but simple pointers

For practice, I've implemented my own smart pointer class. It's a 'unique pointer', meaning it doesn't allow copies of itself (when copying from a into ...
10
votes
2answers
595 views

strend, function that checks the occurence of a pattern at the end of a string

Write a function strend(s, t) which returns 1 if the string t occurs at the end of ...
10
votes
2answers
2k views

Trie Data Structure Implementation in C++11 using Smart Pointers -- follow-up

Link to my first question. Link to my latest source code. I followed @JDługosz recommendations. How does it look? Do you have any further recommendations? Is it better (if possible) to replace ...
10
votes
5answers
2k views

Simple word counter

I've decided to do this by writing a simple word counter. The app gets all the params and outputs all the unique words, each one with a counter: "Hello world Hello" would return "Hello: 2", "world: ...
10
votes
1answer
163 views

Consuming a picnic lunch

I have a number of related classes (Burger, Pizza, Cupcake) with a common base class ...
10
votes
2answers
889 views

An optional<T> implementation

This is an implementation of optional<T> from C++17, it is mostly standard conforming. I'm looking for a review on efficiency, correctness and performance. ...
10
votes
1answer
629 views

Pascal Triangle program in C

I've created a program to calculate Pascal's triangle: ...
9
votes
4answers
4k views

Singly Linked List implementation C++

Linked List C++ I am new to data structures and I have to implement my own data structures for a project. I have made this working Singly Linked List data structure in C++. I would like to ask ...
9
votes
3answers
13k views

Initializing and printing an array using pointers and dynamic allocation in C

I have written a code for basic array creation and printing it's values in C. I would appreciate comments on how it can be improved, and the industry standards. One issue I'm encountering is having ...
9
votes
2answers
16k views

My implementation for std::unique_ptr

I just finished learning about move semantics and realized that a nice practical example for this concept is unique_ptr (it cannot be copied, only moved). For ...
9
votes
4answers
2k 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
34k 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
12k views

DeepPtr: a deep-copying unique_ptr wrapper in C++

When using the pimple idiom it is necessary to represent your "impl" as a forward declared pointer in the header file. This necessitates a lot of boilerplate code to implement the rule of five. ...
9
votes
1answer
601 views

Using smart pointers to construct Binary Search Tree

I have three main questions: Am I using std::unique_ptr correctly here? Using std::move and ...
9
votes
3answers
3k views

Generic stack in C

I tried to implement a generic stack in C using void pointers and tried to keep it as simple as possible by delegating all responsibility to the caller of the ...
8
votes
4answers
4k views

custom smart pointer class template

Kindly provide your review comments: ...
8
votes
3answers
4k views

String comparison using pointers

This piece of code works fine. But I'm wondering if it can be done in a more efficient way. More specifically, this part (*(s1 + i)) if it possible to force it to ...
8
votes
3answers
2k views

Binary Search Tree implementation using smart pointers

I have implemented below code for binary search tree implementation using shared pointer. At present, I have considered only integers. It supports insertion and deletion of values. Also, a print ...
8
votes
2answers
25k views

Traversing an array with a pointer to the array

I was thinking about how to traverse an array without an int iterator, and I'm curious if my answer is good/bad. The first for loop simply populates each element of ...
8
votes
3answers
235 views

Multiplayer GameObject design

I created a really basic game class. A game has GameObject instances, which currently have a position only. This code is running on the client, and in each loop ...
8
votes
2answers
652 views

C program that reads the description of a deterministic finite automaton and builds it

I just got done coding this C program: Read the description of a deterministic finite automaton from standard input. The first line of input is the number of states in the automaton, n n lines follow,...
8
votes
2answers
403 views

Smart pointer or how not to leak a pointer

Wrote a couple of blog articles about smart pointers. Unique Pointer Shared Pointer Constructors for Smart Pointers So I suppose it time to get the result reviewed. This is not supposed to be a ...
8
votes
1answer
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 ...
8
votes
2answers
14k views

Parsing HTTP Headers in C++

I am building a web server from scratch and trying to make certain tasks faster by embedding C code into the mix for performance. Specifically I'm worried about how the ...
8
votes
1answer
2k views

C++ Linked list with smart pointers

This seems to work fine, but I'm very new to C++ and would like any suggestions for improvements. Areas I have the most trouble with are: Namespacing (honestly, it's still half looking stuff up and ...
8
votes
1answer
690 views

Implementation of a new kind of smart pointer in C++

I'm tempted to write a new kind of smart pointer which, I believe, is less intrusive than boost::intrusive_ptr and has the same memory footprint. The code for the ...

1
2 3 4 5
8