Sponsored Content
Full Discussion: shared pointers
Top Forums UNIX for Advanced & Expert Users shared pointers Post 302299876 by uunniixx on Saturday 21st of March 2009 11:18:54 PM
Old 03-22-2009
shared pointers

I am new to shared pointer conceot in C++ and hence require some clarification:

For example:

class A
{
public:
virtual ~A()
{
}
int x;
};
typedef boost::shared_ptr<A> APtr;


APtr getA()
{
return APtr(new A());
}
A::A()
{
x = 0;
}

When ever I call APtr getA() will every instance of object A will see x as 0?
 

10 More Discussions You Might Find Interesting

1. Programming

Pointers and array

hi all, let say i have a pointer exit, and this exit will store some value. how can i store the value that the pointer points to into an array and then print them out from the array. thanks in advance (2 Replies)
Discussion started by: dianazheng
2 Replies

2. Programming

pointers

is this a valid c declaration int (*ptr(int *b)); plz explain... (4 Replies)
Discussion started by: areef4u
4 Replies

3. Programming

Shared memory in shared library

I need to create a shared library to access an in memory DB. The DB is not huge, but big enough to make it cumbersome to carry around in every single process using the shared library. Luckily, it is pretty static information, so I don't need to worry much about synchronizing the data between... (12 Replies)
Discussion started by: DreamWarrior
12 Replies

4. Programming

pointers

Hi I mash with pointers in C. I solve this problem about 5 hours and I don't know how I should continue. void InsertFirst (tList *L, int val) { tElemPtr new; if((new = malloc(sizeof(tElemPtr))) == NULL) Error(); new->data = val; new->ptr = L->frst; L->frst = new;... (2 Replies)
Discussion started by: Milla
2 Replies

5. Programming

restricted pointers

Hi all. I am trying to use restricted pointers to allow the gcc compiler optimize the code, but I have not been able to make it work so far. I am testing with this code: #include <stdlib.h> #include <stdio.h> #include <time.h> #include <sys/time.h> void vecmult(int n, int * restrict a, int... (0 Replies)
Discussion started by: carl.alv
0 Replies

6. Programming

Shared memory for shared library

I am writing a shared library in Linux (but compatible with other UNIXes) and I want to allow multiple instances to share a piece of memory -- 1 byte is enough. What's the "best" way to do this? I want to optimize for speed and portability. Obviously, I'll have to worry about mutual exclusion. (0 Replies)
Discussion started by: otheus
0 Replies

7. Programming

Need help with the Pointers in C

I have a special character called ô. When it is declared as a character variable its showing it can be printed. But when it is declared as a character pointer variable its showing it cannot be printed. I am just wondering why its happening like this.. c1 = '@'; c2 = 'ô'; char *fp; fp="XXô"; if... (1 Reply)
Discussion started by: sivakumar.rj
1 Replies

8. Programming

Pointer to pointers

Hi guys, I'm trying to understand pointers in C and made a simple example and I've problems with It. Can someone help? #include <stdio.h> #include <stdlib.h> #include <assert.h> int f1(char **str_); int main(int argc, char **argv) { char *str = NULL; f1(&str); ... (3 Replies)
Discussion started by: pharaoh
3 Replies

9. Programming

Shared library with acces to shared memory.

Hello. I am new to this forum and I would like to ask for advice about low level POSIX programming. I have to implement a POSIX compliant C shared library. A file will have some variables and the shared library will have some functions which need those variables. There is one special... (5 Replies)
Discussion started by: iamjag
5 Replies

10. Programming

Pointers and array

Hello, I read from a book exercise for a challenge. How to print out each letter of char array a by two different pointers pa and ppa in the example? I have tried my code for letter "r" by testing without full understanding as only the first one worked. #include<stdio.h> int main() { char... (17 Replies)
Discussion started by: yifangt
17 Replies
std::shared_ptr< _Tp >(3cxx)											      std::shared_ptr< _Tp >(3cxx)

NAME
std::shared_ptr< _Tp > - SYNOPSIS
Inherits std::__shared_ptr< _Tp, _Lp >. Public Types typedef _Tp element_type Public Member Functions constexpr shared_ptr () shared_ptr (const shared_ptr &) template<typename _Tp1 > shared_ptr (_Tp1 *__p) template<typename _Tp1 , typename _Deleter > shared_ptr (_Tp1 *__p, _Deleter __d) template<typename _Deleter > shared_ptr (nullptr_t __p, _Deleter __d) template<typename _Tp1 , typename _Deleter , typename _Alloc > shared_ptr (_Tp1 *__p, _Deleter __d, _Alloc __a) template<typename _Deleter , typename _Alloc > shared_ptr (nullptr_t __p, _Deleter __d, _Alloc __a) template<typename _Tp1 > shared_ptr (const shared_ptr< _Tp1 > &__r, _Tp *__p) template<typename _Tp1 , typename = typename std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> shared_ptr (const shared_ptr< _Tp1 > &__r) shared_ptr (shared_ptr &&__r) template<typename _Tp1 , typename = typename std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> shared_ptr (shared_ptr< _Tp1 > &&__r) template<typename _Tp1 > shared_ptr (const weak_ptr< _Tp1 > &__r) template<typename _Tp1 , typename _Del > shared_ptr (std::unique_ptr< _Tp1, _Del > &&__r) constexpr shared_ptr (nullptr_t __p) _Tp * get () const operator bool () const std::add_lvalue_reference< _Tp > ::type operator* () const " _Tp * operator-> () const shared_ptr & operator= (const shared_ptr &) template<typename _Tp1 > shared_ptr & operator= (const shared_ptr< _Tp1 > &__r) shared_ptr & operator= (shared_ptr &&__r) template<class _Tp1 > shared_ptr & operator= (shared_ptr< _Tp1 > &&__r) template<typename _Tp1 , typename _Del > shared_ptr & operator= (std::unique_ptr< _Tp1, _Del > &&__r) template<typename _Tp1 > bool owner_before (__shared_ptr< _Tp1, _Lp > const &__rhs) const template<typename _Tp1 > bool owner_before (__weak_ptr< _Tp1, _Lp > const &__rhs) const void reset () template<typename _Tp1 > void reset (_Tp1 *__p) template<typename _Tp1 , typename _Deleter > void reset (_Tp1 *__p, _Deleter __d) template<typename _Tp1 , typename _Deleter , typename _Alloc > void reset (_Tp1 *__p, _Deleter __d, _Alloc __a) void swap (__shared_ptr< _Tp, _Lp > &__other) bool unique () const long use_count () const Friends template<typename _Tp1 , typename _Alloc , typename... _Args> shared_ptr< _Tp1 > allocate_shared (const _Alloc &__a, _Args &&...__args) Detailed Description template<typename _Tp>class std::shared_ptr< _Tp > A smart pointer with reference-counted copy semantics. The object pointed to is deleted when the last shared_ptr pointing to it is destroyed or reset. Definition at line 93 of file shared_ptr.h. Constructor &; Destructor Documentation template<typename _Tp> constexpr std::shared_ptr< _Tp >::shared_ptr () [inline] Construct an empty shared_ptr. Postcondition: use_count()==0 && get()==0 Definition at line 100 of file shared_ptr.h. template<typename _Tp> template<typename _Tp1 > std::shared_ptr< _Tp >::shared_ptr (_Tp1 *__p) [inline], [explicit] Construct a shared_ptr that owns the pointer __p. Parameters: __p A pointer that is convertible to element_type*. Postcondition: use_count() == 1 && get() == __p Exceptions: std::bad_alloc,in which case delete __p is called. Definition at line 112 of file shared_ptr.h. template<typename _Tp> template<typename _Tp1 , typename _Deleter > std::shared_ptr< _Tp >::shared_ptr (_Tp1 *__p, _Deleter__d) [inline] Construct a shared_ptr that owns the pointer __p and the deleter __d. Parameters: __p A pointer. __d A deleter. Postcondition: use_count() == 1 && get() == __p Exceptions: std::bad_alloc,in which case __d(__p) is called. Requirements: _Deleter's copy constructor and destructor must not throw __shared_ptr will release __p by calling __d(__p) Definition at line 129 of file shared_ptr.h. template<typename _Tp> template<typename _Deleter > std::shared_ptr< _Tp >::shared_ptr (nullptr_t__p, _Deleter__d) [inline] Construct a shared_ptr that owns a null pointer and the deleter __d. Parameters: __p A null pointer constant. __d A deleter. Postcondition: use_count() == 1 && get() == __p Exceptions: std::bad_alloc,in which case __d(__p) is called. Requirements: _Deleter's copy constructor and destructor must not throw The last owner will call __d(__p) Definition at line 146 of file shared_ptr.h. template<typename _Tp> template<typename _Tp1 , typename _Deleter , typename _Alloc > std::shared_ptr< _Tp >::shared_ptr (_Tp1 *__p, _Deleter__d, _Alloc__a) [inline] Construct a shared_ptr that owns the pointer __p and the deleter __d. Parameters: __p A pointer. __d A deleter. __a An allocator. Postcondition: use_count() == 1 && get() == __p Exceptions: std::bad_alloc,in which case __d(__p) is called. Requirements: _Deleter's copy constructor and destructor must not throw _Alloc's copy constructor and destructor must not throw. __shared_ptr will release __p by calling __d(__p) Definition at line 165 of file shared_ptr.h. template<typename _Tp> template<typename _Deleter , typename _Alloc > std::shared_ptr< _Tp >::shared_ptr (nullptr_t__p, _Deleter__d, _Alloc__a) [inline] Construct a shared_ptr that owns a null pointer and the deleter __d. Parameters: __p A null pointer constant. __d A deleter. __a An allocator. Postcondition: use_count() == 1 && get() == __p Exceptions: std::bad_alloc,in which case __d(__p) is called. Requirements: _Deleter's copy constructor and destructor must not throw _Alloc's copy constructor and destructor must not throw. The last owner will call __d(__p) Definition at line 184 of file shared_ptr.h. template<typename _Tp> template<typename _Tp1 > std::shared_ptr< _Tp >::shared_ptr (const shared_ptr< _Tp1 > &__r, _Tp *__p) [inline] Constructs a shared_ptr instance that stores __p and shares ownership with __r. Parameters: <strong>r A shared_ptr. __p A pointer that will remain valid while *r is valid. Postcondition: get() == __p && use_count() == __r.use_count() This can be used to construct a shared_ptr to a sub-object of an object managed by an existing shared_ptr. shared_ptr< pair<int,int> > pii(new pair<int,int>()); shared_ptr<int> pi(pii, &pii->first); assert(pii.use_count() == 2); Definition at line 206 of file shared_ptr.h. template<typename _Tp> template<typename _Tp1 , typename = typename std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> std::shared_ptr< _Tp >::shared_ptr (const shared_ptr< _Tp1 > &__r) [inline] If __r is empty, constructs an empty shared_ptr; otherwise construct a shared_ptr that shares ownership with __r. Parameters: __r A shared_ptr. Postcondition: get() == __r.get() && use_count() == __r.use_count() Definition at line 218 of file shared_ptr.h. template<typename _Tp> std::shared_ptr< _Tp >::shared_ptr (shared_ptr< _Tp > &&__r) [inline] Move-constructs a shared_ptr instance from __r. Parameters: __r A shared_ptr rvalue. Postcondition: *this contains the old value of __r, __r is empty. Definition at line 226 of file shared_ptr.h. template<typename _Tp> template<typename _Tp1 , typename = typename std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type> std::shared_ptr< _Tp >::shared_ptr (shared_ptr< _Tp1 > &&__r) [inline] Move-constructs a shared_ptr instance from __r. Parameters: __r A shared_ptr rvalue. Postcondition: *this contains the old value of __r, __r is empty. Definition at line 236 of file shared_ptr.h. template<typename _Tp> template<typename _Tp1 > std::shared_ptr< _Tp >::shared_ptr (const weak_ptr< _Tp1 > &__r) [inline], [explicit] Constructs a shared_ptr that shares ownership with __r and stores a copy of the pointer stored in __r. Parameters: __r A weak_ptr. Postcondition: use_count() == __r.use_count() Exceptions: bad_weak_ptr when __r.expired(), in which case the constructor has no effect. Definition at line 248 of file shared_ptr.h. template<typename _Tp> constexpr std::shared_ptr< _Tp >::shared_ptr (nullptr_t__p) [inline] Construct an empty shared_ptr. Parameters: __p A null pointer constant. Postcondition: use_count() == 0 && get() == nullptr Definition at line 266 of file shared_ptr.h. Friends And Related Function Documentation template<typename _Tp> template<typename _Tp1 , typename _Alloc , typename... _Args> shared_ptr<_Tp1> allocate_shared (const _Alloc &__a, _Args &&...__args) [friend] Create an object that is owned by a shared_ptr. Parameters: __a An allocator. __args Arguments for the _Tp object's constructor. Returns: A shared_ptr that owns the newly created object. Exceptions: An exception thrown from _Alloc::allocate or from the constructor of _Tp. A copy of __a will be used to allocate memory for the shared_ptr and the new object. Definition at line 532 of file shared_ptr.h. Author Generated automatically by Doxygen for libstdc++ from the source code. libstdc++ Tue Nov 27 2012 std::shared_ptr< _Tp >(3cxx)
All times are GMT -4. The time now is 09:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy