473,394 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Is this Smart Pointer class thread-safe?

I'd like to now if this smart pointer class if thread-safe:

Code:

// COPYRIGHT CMDR DOUGLAS I. PEREIRA 07/10/06
// ALL UNAUTHORIZED THIRD PARTY USE IS PROHIBITED
// I HAVE WORKED VERY HARD AND HAVE SPENT HOURS OF
// TIME DEVELOPING THIS. DO NOT COPY IT OR I WILL SUE YOU
// ************************************************** **********
#pragma once

class SmrtPtrDB
{
public:
SmrtPtrDB(int status=1):num(status){}
SmrtPtrDB(const SmrtPtrDB& rhs):num(rhs.num){}
~SmrtPtrDB(){}
void add(){num++;}
void sub(){num--;}
int status(){return num;}
private:
int num;
};

// COPYRIGHT CMDR DOUGLAS I. PEREIRA 07/10/06
// ALL UNAUTHORIZED THIRD PARTY USE IS PROHIBITED
// I HAVE WORKED VERY HARD AND HAVE SPENT HOURS OF
// TIME DEVELOPING THIS. DO NOT COPY IT OR I WILL SUE YOU
// ************************************************** **********
#pragma once
#include <iostream>
#include <algorithm>
#include "SmrtPtrDB.hpp"
using std::cout;
using std::endl;
class NullPtr{};

template<class T>
class SmrtPtr
{
public:
explicit SmrtPtr<T>(T* obj=0):ptr(obj),DataBase(new SmrtPtrDB){}
SmrtPtr<T>(const SmrtPtr<T>& rhs):ptr(rhs.ptr),DataBase(new
SmrtPtrDB(rhs.DataBase->status()))
{DataBase->add();}
~SmrtPtr<T>()
{
DataBase->sub();
if(DataBase->status()==0)
{delete ptr; delete DataBase; cout << "Deleted." << endl;}
else {delete DataBase; cout << "Out of scope. " << endl;}
}
void operator=(T* val)
{
SmrtPtr<Ttemp(val);
swap(temp);
}
SmrtPtr<T>& operator=(const SmrtPtr<T>& rhs)
{
SmrtPtr<Ttemp(rhs);
swap(temp);
return *this;
}
bool operator==(const SmrtPtr<T>& rhs)const{if(ptr==rhs.ptr)return
true;else return false;}
bool operator!=(const SmrtPtr<T>& rhs)const{if(ptr!=rhs.ptr)return
true;else return false;}
bool operator<=(const SmrtPtr<T>& rhs)const{if(ptr<=rhs.ptr)return
true;else return false;}
bool operator>=(const SmrtPtr<T>& rhs)const{if(ptr>=rhs.ptr)return
true;else return false;}
int status(){return DataBase->status();}
T& operator*()const{if(ptr==0)throw NullPtr();else return *ptr;}
T* operator->()const{if(ptr==0)throw NullPtr();else return ptr;}
operator T*()const{if(ptr==0)throw NullPtr();else return ptr;}
private:
void swap(SmrtPtr<T>& rhs)
{
std::swap(DataBase,rhs.DataBase);
std::swap(ptr,rhs.ptr);
}
mutable SmrtPtrDB* DataBase;
T* ptr;
};

Is this the right way to implement ref-counting? Any input would be
greatly appreciated. Thanks!!!!!

Aug 9 '06 #1
28 2777
Protoman wrote:
I'd like to now if this smart pointer class if thread-safe:

Code:

// COPYRIGHT CMDR DOUGLAS I. PEREIRA 07/10/06
// ALL UNAUTHORIZED THIRD PARTY USE IS PROHIBITED
// I HAVE WORKED VERY HARD AND HAVE SPENT HOURS OF
// TIME DEVELOPING THIS. DO NOT COPY IT OR I WILL SUE YOU
// ************************************************** **********
Sorry, I couldn't make a copy to compile and test because I might get sued.

--
Alan Johnson
Aug 9 '06 #2

Alan Johnson wrote:
Protoman wrote:
I'd like to now if this smart pointer class if thread-safe:

Code:

// COPYRIGHT CMDR DOUGLAS I. PEREIRA 07/10/06
// ALL UNAUTHORIZED THIRD PARTY USE IS PROHIBITED
// I HAVE WORKED VERY HARD AND HAVE SPENT HOURS OF
// TIME DEVELOPING THIS. DO NOT COPY IT OR I WILL SUE YOU
// ************************************************** **********

Sorry, I couldn't make a copy to compile and test because I might get sued.

--
Alan Johnson
I hereby authorize you to use this code for a one-time test. After
that, you must purge your computer memory, and also your short-term and
long-term memory of this code. I won't sue YOU; that was just in case a
software company, ie MS, tried to use it in production code. Test away.

Aug 9 '06 #3
I'd like to now if this smart pointer class if thread-safe:
No, it's not.
class SmrtPtrDB
Why do you need this? Can't you keep the reference count inside your
SmartPtr?
SmrtPtrDB(int status=1):num(status)
Why do you need the parameter here?

Aug 9 '06 #4
Protoman wrote:
I'd like to now if this smart pointer class if thread-safe:

Code:

// COPYRIGHT CMDR DOUGLAS I. PEREIRA 07/10/06
// ALL UNAUTHORIZED THIRD PARTY USE IS PROHIBITED
// I HAVE WORKED VERY HARD AND HAVE SPENT HOURS OF
// TIME DEVELOPING THIS. DO NOT COPY IT OR I WILL SUE YOU
// ************************************************** **********
#pragma once

class SmrtPtrDB
{
public:
SmrtPtrDB(int status=1):num(status){}
SmrtPtrDB(const SmrtPtrDB& rhs):num(rhs.num){}
~SmrtPtrDB(){}
void add(){num++;}
void sub(){num--;}
int status(){return num;}
private:
int num;
};

// COPYRIGHT CMDR DOUGLAS I. PEREIRA 07/10/06
// ALL UNAUTHORIZED THIRD PARTY USE IS PROHIBITED
// I HAVE WORKED VERY HARD AND HAVE SPENT HOURS OF
// TIME DEVELOPING THIS. DO NOT COPY IT OR I WILL SUE YOU
// ************************************************** **********
#pragma once
#include <iostream>
#include <algorithm>
#include "SmrtPtrDB.hpp"
using std::cout;
using std::endl;
class NullPtr{};

template<class T>
class SmrtPtr
{
public:
explicit SmrtPtr<T>(T* obj=0):ptr(obj),DataBase(new SmrtPtrDB){}
SmrtPtr<T>(const SmrtPtr<T>& rhs):ptr(rhs.ptr),DataBase(new
SmrtPtrDB(rhs.DataBase->status()))
{DataBase->add();}
~SmrtPtr<T>()
{
DataBase->sub();
if(DataBase->status()==0)
{delete ptr; delete DataBase; cout << "Deleted." << endl;}
else {delete DataBase; cout << "Out of scope. " << endl;}
}
void operator=(T* val)
{
SmrtPtr<Ttemp(val);
swap(temp);
}
SmrtPtr<T>& operator=(const SmrtPtr<T>& rhs)
{
SmrtPtr<Ttemp(rhs);
swap(temp);
return *this;
}
bool operator==(const SmrtPtr<T>& rhs)const{if(ptr==rhs.ptr)return
true;else return false;}
bool operator!=(const SmrtPtr<T>& rhs)const{if(ptr!=rhs.ptr)return
true;else return false;}
bool operator<=(const SmrtPtr<T>& rhs)const{if(ptr<=rhs.ptr)return
true;else return false;}
bool operator>=(const SmrtPtr<T>& rhs)const{if(ptr>=rhs.ptr)return
true;else return false;}
int status(){return DataBase->status();}
T& operator*()const{if(ptr==0)throw NullPtr();else return *ptr;}
T* operator->()const{if(ptr==0)throw NullPtr();else return ptr;}
operator T*()const{if(ptr==0)throw NullPtr();else return ptr;}
private:
void swap(SmrtPtr<T>& rhs)
{
std::swap(DataBase,rhs.DataBase);
std::swap(ptr,rhs.ptr);
}
mutable SmrtPtrDB* DataBase;
T* ptr;
};

Is this the right way to implement ref-counting? Any input would be
greatly appreciated. Thanks!!!!!
I don't have the book handy at the moment... but "More Effective C++" by
Scott Meyers dedicates a section or two to Smart Pointers and Reference
Counting, worth looking into...

Aug 9 '06 #5
Jeremy Brown wrote:
Protoman wrote:
I'd like to now if this smart pointer class if thread-safe:
[snip]
I don't have the book handy at the moment... but "More Effective C++" by
Scott Meyers dedicates a section or two to Smart Pointers and Reference
Counting, worth looking into...
So does chapter 7 of _Modern C++ Design_ by Alexandrescu, which also
deals with multithreading issues. In fact, the chapter is online for
free:

http://www.informit.com/articles/pri...p?p=25264&rl=1

There is also a series of four columns by Alexandrescu and Held from
CUJ that revisits the design from _MC++D_:

http://www.ddj.com/dept/cpp/184403875

Cheers! --M

Aug 9 '06 #6
Protoman wrote:
[snip illegible code]
Is this the right way to implement ref-counting? Any input would be
greatly appreciated.
Here's my input: format your code so it's readable by others.
Whitespace does not slow your software down.

Cheers! --M

Aug 9 '06 #7

Protoman wrote:
I'd like to now if this smart pointer class if thread-safe:

Code:

// COPYRIGHT CMDR DOUGLAS I. PEREIRA 07/10/06
// ALL UNAUTHORIZED THIRD PARTY USE IS PROHIBITED
// I HAVE WORKED VERY HARD AND HAVE SPENT HOURS OF
// TIME DEVELOPING THIS. DO NOT COPY IT OR I WILL SUE YOU
// ************************************************** **********
[snip student code]

why on the earth anyone would copy that bunch of crap?

save your threats to something more valuable

and how I will got sued if I copy your "little precious" code into my
softwares? you don't seem to have the reverse engineering profile

you don't even know about critical sections. better finish the
operating system class or become a lawyer before trying to sue the
people ;-)

Aug 9 '06 #8

Diego Martins wrote:
Protoman wrote:
I'd like to now if this smart pointer class if thread-safe:

Code:

// COPYRIGHT CMDR DOUGLAS I. PEREIRA 07/10/06
// ALL UNAUTHORIZED THIRD PARTY USE IS PROHIBITED
// I HAVE WORKED VERY HARD AND HAVE SPENT HOURS OF
// TIME DEVELOPING THIS. DO NOT COPY IT OR I WILL SUE YOU
// ************************************************** **********

[snip student code]

why on the earth anyone would copy that bunch of crap?

save your threats to something more valuable

and how I will got sued if I copy your "little precious" code into my
softwares? you don't seem to have the reverse engineering profile

you don't even know about critical sections. better finish the
operating system class or become a lawyer before trying to sue the
people ;-)
There's ALWAYS a possibility. And besides, I'm a HS Freshman. And I
REALLY need to take some CE and Advanced C++ classes at CSULB, don't I?

Aug 9 '06 #9
On 9 Aug 2006 13:46:03 -0700, "Protoman" <Pr**********@gmail.com>
wrote:
>
Diego Martins wrote:
>Protoman wrote:
I'd like to now if this smart pointer class if thread-safe:

Code:

// COPYRIGHT CMDR DOUGLAS I. PEREIRA 07/10/06
// ALL UNAUTHORIZED THIRD PARTY USE IS PROHIBITED
// I HAVE WORKED VERY HARD AND HAVE SPENT HOURS OF
// TIME DEVELOPING THIS. DO NOT COPY IT OR I WILL SUE YOU
// ************************************************** **********

[snip student code]

why on the earth anyone would copy that bunch of crap?

save your threats to something more valuable

and how I will got sued if I copy your "little precious" code into my
softwares? you don't seem to have the reverse engineering profile

you don't even know about critical sections. better finish the
operating system class or become a lawyer before trying to sue the
people ;-)

There's ALWAYS a possibility. And besides, I'm a HS Freshman. And I
REALLY need to take some CE and Advanced C++ classes at CSULB, don't I?
You CAN just learn stuff yourself, you know.
Aug 9 '06 #10
ya****@gmail.com schrieb:
>class SmrtPtrDB
Why do you need this? Can't you keep the reference count inside your
SmartPtr?
Show me a working solution, please! :-)

--
Thomas
Aug 9 '06 #11

Thomas J. Gritzan написав:
ya****@gmail.com schrieb:
class SmrtPtrDB
Why do you need this? Can't you keep the reference count inside your
SmartPtr?

Show me a working solution, please! :-)

--
Thomas
You can do that for yourself. Google helps alot.

For example, this one http://ootips.org/yonat/4dev/counted_ptr.h ? If
you don't it one here you can find more
http://www.codeproject.com/cpp/smartptr.asp .

Aug 9 '06 #12

W Marsh wrote:
On 9 Aug 2006 13:46:03 -0700, "Protoman" <Pr**********@gmail.com>
wrote:

Diego Martins wrote:
Protoman wrote:
I'd like to now if this smart pointer class if thread-safe:

Code:

// COPYRIGHT CMDR DOUGLAS I. PEREIRA 07/10/06
// ALL UNAUTHORIZED THIRD PARTY USE IS PROHIBITED
// I HAVE WORKED VERY HARD AND HAVE SPENT HOURS OF
// TIME DEVELOPING THIS. DO NOT COPY IT OR I WILL SUE YOU
// ************************************************** **********

[snip student code]

why on the earth anyone would copy that bunch of crap?

save your threats to something more valuable

and how I will got sued if I copy your "little precious" code into my
softwares? you don't seem to have the reverse engineering profile

you don't even know about critical sections. better finish the
operating system class or become a lawyer before trying to sue the
people ;-)
There's ALWAYS a possibility. And besides, I'm a HS Freshman. And I
REALLY need to take some CE and Advanced C++ classes at CSULB, don't I?

You CAN just learn stuff yourself, you know.
Listen buddy, I've BEEN learning this stuff myself for the past five
YEARS. A college class would be a nice supplement to spending hours
reading reference books and comp.lang.c++.

Aug 9 '06 #13
ya****@gmail.com schrieb:
Thomas J. Gritzan написав:
>ya****@gmail.com schrieb:
>>>class SmrtPtrDB
Why do you need this? Can't you keep the reference count inside your
SmartPtr?
Show me a working solution, please! :-)
You can do that for yourself. Google helps alot.
I wanted to say: It's hardly possible.

A reference counted smart pointer has to share the pointee and the
reference count with its instances, so there are two common approaches:

- intrusive: The counter is inside the pointee, the smart pointer calls
member functions like AddRef() and Release().
- non-intrusive: The smart pointer allocates an extra counter (either a
class or a simple "unsigned int")
For example, this one http://ootips.org/yonat/4dev/counted_ptr.h ?
From the Website:
[...]
private:

struct counter {
counter(X* p = 0, unsigned c = 1) : ptr(p), count(c) {}
X* ptr;
unsigned count;
}* itsCounter;
[...]

This implementation also uses an extra class for the reference count.
The difference is that the extra class is declared inside the smart
pointer class and also holds the pointer to the pointee.
If you don't it one here you can find more
http://www.codeproject.com/cpp/smartptr.asp .
This also, but it uses a policy based approach.

--
Thomas
http://www.netmeister.org/news/learn2quote.html
Aug 9 '06 #14
Protoman wrote:
Diego Martins wrote:
>>>
// COPYRIGHT CMDR DOUGLAS I. PEREIRA 07/10/06
[redacted]
[redacted]
There's ALWAYS a possibility. And besides, I'm a HS Freshman. And I
REALLY need to take some CE and Advanced C++ classes at CSULB, don't I?
But wait! I thought you were a rocket scientist! And your copyright
notice indicates you're a Commander in some sort of Naval service!
Aug 9 '06 #15
Protoman posted:
>You CAN just learn stuff yourself, you know.

Listen buddy, I've BEEN learning this stuff myself for the past five
YEARS. A college class would be a nice supplement to spending hours
reading reference books and comp.lang.c++.

Perhaps you're just stupid then. All of my programming expertise is a product
of:

(1) Learning from books.
(2) Practising.
(3) Reading and posting to comp.lang.*

From what I've seen of them, lecturers are a poor substitute for motivated
self-learning.

--

Frederick Gotham
Aug 9 '06 #16
Protoman wrote:
I'd like to now if this smart pointer class if thread-safe:

Code:
(snip)
>
Is this the right way to implement ref-counting? Any input would be
greatly appreciated. Thanks!!!!!
If you want atomically thread-safe and not merely "thread-safe as int",
take a look at
http://groups.google.com/groups?hl=e...8%40xemaps.com

The cas64 is ibm style cas rather than msoft style cas. It's in assembler and
there might be some examples online somewhere. There used to be a version
downloadable from my sourceforge project page but it was such a good algorithm
that Sun has decided to patent it as their own invention. Seriously. Look
up patent application
20060037026 'Lightweight reference counting using single-target synchronization'
on upto.gov. There's some really nice illustrations in the patent application
though.

--
Joe Seigh

When you get lemons, you make lemonade.
When you get hardware, you make software.
Aug 9 '06 #17

Frederick Gotham wrote:
Protoman posted:
You CAN just learn stuff yourself, you know.
Listen buddy, I've BEEN learning this stuff myself for the past five
YEARS. A college class would be a nice supplement to spending hours
reading reference books and comp.lang.c++.


Perhaps you're just stupid then. All of my programming expertise is a product
of:

(1) Learning from books.
(2) Practising.
(3) Reading and posting to comp.lang.*

From what I've seen of them, lecturers are a poor substitute for motivated
self-learning.

--

Frederick Gotham
Damn it, I *AM* self-motivated!!!! How did I spend five years learning
something w/o self-motivation?!!!?

Aug 9 '06 #18
Protoman posted:
>Perhaps you're just stupid then. All of my programming expertise is a
product of:

(1) Learning from books.
(2) Practising.
(3) Reading and posting to comp.lang.*

From what I've seen of them, lecturers are a poor substitute for
motivated self-learning.
Damn it, I *AM* self-motivated!!!! How did I spend five years learning
something w/o self-motivation?!!!?

Then try harder. I've been programming in C++ for approximately 5 years, and
my proficiency far surpasses yours.

Get good books. Ask questions. Practise.

--

Frederick Gotham
Aug 9 '06 #19
red floyd wrote:
Protoman wrote:
Diego Martins wrote:

// COPYRIGHT CMDR DOUGLAS I. PEREIRA 07/10/06
[redacted]
[redacted]
There's ALWAYS a possibility. And besides, I'm a HS Freshman. And I
REALLY need to take some CE and Advanced C++ classes at CSULB,
don't I?

But wait! I thought you were a rocket scientist! And your copyright
notice indicates you're a Commander in some sort of Naval service!
I killfiled this Protoman twit from a previous "visit" to the
newsgroup.


Brian
Aug 9 '06 #20

Default User wrote:
red floyd wrote:
Protoman wrote:
Diego Martins wrote:
>
// COPYRIGHT CMDR DOUGLAS I. PEREIRA 07/10/06
[redacted]
[redacted]
There's ALWAYS a possibility. And besides, I'm a HS Freshman. And I
REALLY need to take some CE and Advanced C++ classes at CSULB,
don't I?
>
But wait! I thought you were a rocket scientist! And your copyright
notice indicates you're a Commander in some sort of Naval service!

I killfiled this Protoman twit from a previous "visit" to the
newsgroup.


Brian
That just a title my friends apply to me. I do plan on going to NROTC
when I'm in college. Let's just get back OT.

Aug 10 '06 #21

Protoman wrote:
Default User wrote:
red floyd wrote:
Protoman wrote:
Diego Martins wrote:

// COPYRIGHT CMDR DOUGLAS I. PEREIRA 07/10/06
[redacted]
[redacted]
There's ALWAYS a possibility. And besides, I'm a HS Freshman. And I
REALLY need to take some CE and Advanced C++ classes at CSULB,
don't I?

>
But wait! I thought you were a rocket scientist! And your copyright
notice indicates you're a Commander in some sort of Naval service!
I killfiled this Protoman twit from a previous "visit" to the
newsgroup.


Brian

That just a title my friends apply to me. I do plan on going to NROTC
when I'm in college. Let's just get back OT.
I would like to point out that you are impersonating a military
officer, and that I should report you to the Naval Criminal
Investigative Service. Don't copyright anything with a fake name,
unless it is a business and you have filed the proper paperwork

Aug 10 '06 #22

Protoman wrote:
I'd like to now if this smart pointer class if thread-safe:

Code:

// COPYRIGHT CMDR DOUGLAS I. PEREIRA 07/10/06
// ALL UNAUTHORIZED THIRD PARTY USE IS PROHIBITED
// I HAVE WORKED VERY HARD AND HAVE SPENT HOURS OF
// TIME DEVELOPING THIS. DO NOT COPY IT OR I WILL SUE YOU
// ************************************************** **********
I would also like to point out that if you do not register your
copyright with the US Copyright Office you cannot sue over copyright.
If you would liek attorney's fees paid you must do it within 3 months
of publication, and the evidence will be considered prima facie only if
you register within 5 years of publication.

Aug 10 '06 #23

cdcarter wrote:
Protoman wrote:
Default User wrote:
red floyd wrote:
>
Protoman wrote:
Diego Martins wrote:
>
// COPYRIGHT CMDR DOUGLAS I. PEREIRA 07/10/06
[redacted]
[redacted]
There's ALWAYS a possibility. And besides, I'm a HS Freshman. And I
REALLY need to take some CE and Advanced C++ classes at CSULB,
don't I?
>

But wait! I thought you were a rocket scientist! And your copyright
notice indicates you're a Commander in some sort of Naval service!
>
I killfiled this Protoman twit from a previous "visit" to the
newsgroup.
>
>
>
>
Brian
That just a title my friends apply to me. I do plan on going to NROTC
when I'm in college. Let's just get back OT.

I would like to point out that you are impersonating a military
officer, and that I should report you to the Naval Criminal
Investigative Service. Don't copyright anything with a fake name,
unless it is a business and you have filed the proper paperwork
Never said I was a *Naval* Commander, now did I? There ARE other ways
you can get the title of "Commander", like there are other ways of
getting the title "Colonel".

Aug 11 '06 #24
In article <11**********************@74g2000cwt.googlegroups. com>,
cd******@gmail.com says...

[ ... ]
I would also like to point out that if you do not register your
copyright with the US Copyright Office you cannot sue over copyright.
OT, but yes, you can sue for infringement of an unregistered copyright.
You can't be awarded damages if you win, but you can get a court order
for the infringing party to stop. Of course, given that this newsgroup
is distributed internationally, there are undoubtedly quite a few
participants for whom the rules are entirely different, and for whom the
US copyright office is of little or no consequence.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Aug 11 '06 #25
Never said I was a *Naval* Commander, now did I? There ARE other ways
you can get the title of "Commander", like there are other ways of
getting the title "Colonel".

Klingon Commander?

Aug 11 '06 #26

au**************@gmail.com wrote:
Never said I was a *Naval* Commander, now did I? There ARE other ways
you can get the title of "Commander", like there are other ways of
getting the title "Colonel".


Klingon Commander?
Sure, why not? I like Star Trek: TNG.

Aug 11 '06 #27

Protoman wrote:
au**************@gmail.com wrote:
Never said I was a *Naval* Commander, now did I? There ARE other ways
you can get the title of "Commander", like there are other ways of
getting the title "Colonel".

Klingon Commander?

Sure, why not? I like Star Trek: TNG.
You are the commander of the gay pride

Aug 14 '06 #28
Diego Martins wrote:
Protoman wrote:
au**************@gmail.com wrote:
Never said I was a *Naval* Commander, now did I? There ARE other ways
you can get the title of "Commander", like there are other ways of
getting the title "Colonel".
>
>
Klingon Commander?
Sure, why not? I like Star Trek: TNG.

You are the commander of the gay pride
Please stop this nonsense. Comment on the code, not the person.

Cheers! --M

Aug 14 '06 #29

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sreeram | last post by:
Hello, I am having a doubt about smart pointer. I wrote a smart ptr class with limited functionalities. I want to do like this! CSmartPtr <CSomeClass> test = new CSomeClass; // here i need to...
6
by: Johnny Hansen | last post by:
Hello, I've been trying to implement smart pointers in C++ (combined with a reference counter) because I want to do some memory management. My code is based on the gamedev enginuity articles,...
3
by: Vijai Kalyan | last post by:
I have been thinking about this and it may have already been thrashed out and hung out to dry as a topic of no more interest but here goes. I found when implementing a smart pointer that the...
4
by: Matthias Kaeppler | last post by:
Hi, I'm having a hard time figuring out how I can initialize a smart pointer based on a certain condition: if something then ptr = 0; // init with NULL else ptr = new XYZ; // init with a...
5
by: Boris | last post by:
I've a class C with a smart pointer (I use boost::shared_ptr) which is initialized in the constructor: class C { boost::shared_ptr<D> d; public: C() : d(new d()) { } }; When the program...
92
by: Jim Langston | last post by:
Someone made the statement in a newsgroup that most C++ programmers use smart pointers. His actual phrase was "most of us" but I really don't think that most C++ programmers use smart pointers,...
14
by: Ian | last post by:
I am looking at porting code from a C++ application to C#. This requires implementing data sharing functionality similar to what is provided by a smart pointer in C++. I have only recently begun...
33
by: Ney Andr de Mello Zunino | last post by:
Hello. I have written a simple reference-counting smart pointer class template called RefCountPtr<T>. It works in conjunction with another class, ReferenceCountable, which is responsible for the...
10
by: =?iso-8859-1?q?Ernesto_Basc=F3n?= | last post by:
I am implementing my custom smart pointer: template <typename T> class MySmartPtr { public: MySmartPtr(T* aPointer) { mPointer = aPointer; }
50
by: Juha Nieminen | last post by:
I asked a long time ago in this group how to make a smart pointer which works with incomplete types. I got this answer (only relevant parts included): ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.