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.

learn more… | top users | synonyms (1)

16
votes
5answers
1k 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 ...
2
votes
2answers
50 views

Linked list insertion

I have written the code below for inserting an element at the position specified by the user. I have seen the code in multiple books, and they have always used two pointers in the function that ...
8
votes
2answers
94 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 ...
3
votes
2answers
74 views

Finding the min and max of an array, using a pointer

Modify the maxmin.c program so that the max min function uses a pointer instead of an integer to keep track of the current position in the array. maxmin.c ...
4
votes
2answers
63 views

A clone_ptr<T> that does not require T to have a clone method

Here is my clone pointer template: ...
1
vote
2answers
63 views

Build a time struct for current time in UTC

I'm learning about time structs. Without assigning either in code or input routines I want the current time. Please help me refactor this, if it should be. This code just tries to make a time struct ...
4
votes
2answers
51 views

Merge Sort in Perl

I'm new to Perl and have successfully written a merge sort program. I'll paste the entire program below, but would like mostly a review of the subroutines ...
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 ...
-2
votes
2answers
67 views
1
vote
2answers
143 views

Implementation of unique_ptr and make_unique for aligned memory

I am working on a version of std::unique_ptr and std::make_unique for aligned memory. The purpose of this is vectorization, ...
1
vote
1answer
51 views

Casting between types for shared_ptr

I'm implementing an Entity-Component-System. Basically, an entity is a wrapper around an ID, a component is just a POD struct, and a System is a class that does work on components corresponding to the ...
1
vote
2answers
63 views

C++ smart pointer class

...
5
votes
1answer
71 views

Single LinkedList using smart pointers

In order to learn C++11, I propose to myself implement a simple single linked list using smart pointers. The idea was to cover the basic operations without leave any memory leak. I came up with a ...
8
votes
1answer
118 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
vote
3answers
139 views

Writing the function strend()

Due to being unable to ask a C programming language expert or advanced user in person, I'm posting this simple question about my C code. Today I was refreshing my C with exercise 5.4 of the C ...
3
votes
1answer
96 views

Remove odd valued nodes from linked list

The function remove_odd is to remove odd valued nodes (surprise!!) from the linked list head. The code is very long and cryptic but it seems to work. Please help ...
4
votes
1answer
73 views

Smart pointer mark II - my answer to C++ 11 shared_ptr

I am writing this smart pointer as a learning exercise. Any feedback would be most appreciated. Any flaws? Have I missed any test cases? smart_pointer.hpp: ...
6
votes
3answers
242 views

Reading, echoing, and returning integers in an array

I was wanting some clarification on my code, as I am new to pointers in C. I am trying to return an array from a simple function just so I can understand exactly what it is that I'm doing. Here is ...
4
votes
1answer
107 views

Truncate 160-bit output from SHA-1 to 64-bit uint64_t

I'd like to truncate 160-bit output from SHA-1 to receive a (weaker) 64-bit digest. It has been a while since I did the type of low-level C pointer arithmetic in the but-last line. Could you please ...
10
votes
3answers
962 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 ...
4
votes
2answers
277 views

C++ smart pointers and classes

I've started learning C++ recently and want from what I've gathered smart pointers are the way to go when storing stuff on the free store. I want to make sure I've got the basic hang of C++(11) ...
3
votes
1answer
40 views

Returning the next node

What is considered to be a good programming practice for returning value from the function? For example, if we have a function in C named ...
2
votes
1answer
81 views

Pointer handle - absolute follow-up

This is a follow-up to: Pointer handle - follow-up Improved pointer handle Pointer handle with some runtime checking Please review my pointer class. ...
4
votes
2answers
68 views

Pointer handle - follow-up

This is a followup to: Pointer handle with some runtime checking Improved pointer handle Please review this pointer class. ...
3
votes
3answers
501 views

isPalindrome in C++ using pointers [closed]

I am just beginning to learn C++. I have experience with other languages, mainly C# and Java, so pointers are repetitively new to me. Below I have implemented a function which checks if the given ...
2
votes
1answer
66 views

Improved pointer handle

Please review my improved pointer class. ...
6
votes
1answer
63 views

Pointer handle with some runtime checking

This is a pointer class of mine that I would like to have reviewed. Right now it only allocates in the stack and has no copy or move operations. ...
2
votes
2answers
138 views

Yet another smart pointer implementation for learning

I based this implementation on CountedPtr in The C++ Standard Library book by Nicolai Josuttis (page 222) and also available online here. I know that I can use the C++11 smart pointers but this is a ...
6
votes
3answers
3k 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. ...
2
votes
2answers
117 views

Basic myVector class raw vs smart pointer

I'm writing a myVector class for a class I'm taking. I don't believe I'm "strong" with smart pointers right now, so that's my question. This is just an excerpt ...
4
votes
4answers
217 views

Printing out all possible combination of printable ASCII 7-bit characters to stdout

This takes over 60 minutes to execute. The program is small in size, about 16kb. I am thinking that the repeated calls to printf slows it down significantly, rather ...
6
votes
4answers
3k views

Using std::unique_ptr and std::move

I'm trying out new things (on class Inproc), specifically using std::unique_ptr and ...
4
votes
0answers
134 views

Wrap function pointers in template classes

I'm working on a C++ library for Arduino and other embedded systems. I'm currently working on wrapping up function pointers and member-function pointers into two C++ template classes (function and ...
1
vote
2answers
441 views

Binary search tree with templates

I am currently attempting to become proficient in C++ and started by implementing a basic binary search tree. Most of the programming I have done is in Ada, Python and C. I would like to be able to ...
5
votes
2answers
277 views

Constructing a graph and performing a depth-first traversal

Please review the use of pointers and design in graph construction code and its depth first traversal. I haven't used smart pointers as I want to understand any issues in following implementation with ...
0
votes
2answers
82 views

Deleting values from std::vector of different types

I need to make a vector of different types and be able to delete the values (please ignore anything else but deleting the values for now). Is the next code safe to delete the values? ...
0
votes
1answer
296 views

Polymorphic template cloning class

I have a requirement of a templated clone() method which Base classes can implement through an ICloneable interface and all the ...
10
votes
2answers
563 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 ...
1
vote
2answers
121 views

Speeding up and shortening a loop [closed]

I'm still relatively new to C++ and I've written a program that could do with being a bit shorter and faster. I use this same set of for loops many times to cycle through the whole tree of values. ...
6
votes
5answers
373 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, ...
4
votes
1answer
2k views

Implement a string in reverse using pointers and recursion

I'm trying to reverse a string using pointers and recursion, and I send it a char array. Is this the best way, or is there a better one? ...
3
votes
3answers
250 views

Simple shared pointer

I wrote a simple shared pointer, which I think works pretty well. I would like to see your review of it. This is the header file: ...
6
votes
2answers
337 views

Layer Stack class to practice std::shared_ptr

The following three source files is to define and test a class StackLayer. While it was written in a need for scalable layer-based architecture design, it was also ...
5
votes
2answers
257 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 ...
4
votes
1answer
208 views

Builder/named argument/fluent interface pattern with unique_ptr

I'm trying to figure out the cleanest way to implement a fluent interface with unique_ptr and other "modern" C++ language constructs. Here's my first attempt: ...
7
votes
2answers
3k views
3
votes
1answer
350 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 ...
2
votes
2answers
118 views

Pointers for struct and `for`

I know something about pointers, but I'm trying to check my knowledge on a sample. Can somebody check if my code is good? I don't think that I should use pointers in these ...
3
votes
2answers
1k views

Binary Tree with C++11 smart pointers

I'm trying to replace the use of raw pointers with smart pointers in my C++ code. The following bit is from my first attempt at a self-balancing binary tree, though there is nothing self-balancing at ...
1
vote
1answer
107 views

One more shared pointer

Here's a (hopefully) better shared pointer than the previous one. The improvement is that now it should also accept function and lambda objects. Should work fine with threads. ...