Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8300471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:34:17+00:00 2026-06-08T16:34:17+00:00

Let’s say I have the following function (where mVertexShader is an std::shared_ptr< ID3D11VertexShader >

  • 0

Let’s say I have the following function (where mVertexShader is an std::shared_ptr< ID3D11VertexShader > class member, and mRenderData is just POD holding other D3D stuff):

void VertexShader::CreateShader( void )
{
    GVertexShader* raw_VertexShader = mVertexShader.get();

    mRenderData->Device->CreateVertexShader(
        mCompiledShader->GetBufferPointer(),
        mCompiledShader->GetBufferSize(),
        NULL,
        &raw_VertexShader
    );

    delete raw_VertexShader;
    raw_VertexShader = NULL;
} 

since mVertexShader.get() returns the raw pointer, will deleting raw_VertexShader effect the pointer inside mVertexShader.get(), or, while the memory being pointed to is the same, the pointers themselves are completely different?

I’m guessing the latter, hence why reference-to-pointer exists in the first place, but I’d like to be sure that I have the right idea.

Note: I am currently using MSVC++, though it would be nice to hear whether or not there are any significant differences in how MSVC++ and MinGW/GCC implement this.

Note2: I apologize if I wasn’t being clear – I’m not referring to semantics of D3D here at all, but more so the semantics of the language of C++ itself in regards to memory management, data transfer, and dynamic memory allocation. In that sense, what I’m trying to understand exactly what happens when a raw pointer is returned from a function.

I.e., assuming mVertexShader is storing a simple raw pointer to an arbitrary VertexShader, when I call its get() method, does it return a copied pointer which points to the same memory address being referenced as the one which sits inside the shared_ptr container, or is it an entirely new pointer altogether that has been copied and returned, with memory being to pointed to at a different address?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:34:19+00:00Added an answer on June 8, 2026 at 4:34 pm

    This is actually entirely about the semantics of std::shared_ptr. The language is perfectly happy to support methods of returning a pointer to an object, making a copy of an object and returning a pointer to that, or bumping the reference count on an object and returning a pointer to it. You can do all of those things if you want to.

    The get method on a shared pointer just returns the raw pointer to the object. No copy is made. You should never delete this pointer for two reasons:

    1. Another object might have a shared pointer to the same object and you’d be deleting the object out from under it. (That’s the point of shared pointers.)

    2. When the last shared pointer goes away, the object will be deleted. Deleting an object twice is UB and can cause your code to crash. (That’s also the point of shared pointers.)

    Let the shared pointers do their job.

    Note that if you call get on a shared pointer, you should make sure you keep that shared pointer around for as long as you might use the raw pointer that you got. Otherwise, the object may cease to exist. The logic of shared pointers is that as long as you keep at least one shared pointer around that references an object, it will not be deleted and when the last such shared pointer goes away, the object deletes automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have the following classes : public class MyProductCode { private String
Let's say I have the following function in C#: void ProcessResults() { using (FormProgress
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say we have the following: abstract class A; class B : public A;
Let's say I have a class Base with a single member message (String). Another
Let me explain best with an example. Say you have node class that can
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
Let say I have the following desire, to simplify the IConvertible's to allow me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.