Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Call for Design Comments


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 greenvertex   Members   -  Reputation: 510

Like
0Likes
Like

Posted 08 November 2012 - 11:58 AM

I'd really like some opinions on the following idea:

struct DXBundle {
  ID3D11Device* device;
  ID3D11DeviceContext* context;
  D3D_FEATURE_LEVEL* featureLevel;
 
  DXBundle() {
    UINT createFlags = 0;
#if _DEBUG
    createFlags |= D3D11_CREATE_DEVICE_DEBUG;
#endif
    return D3D11CreateDevice(
	  0, D3D_DRIVER_TYPE_HARDWARE, 0, createFlags,
	  0, 0, D3D11_SDK_VERSION, device, featureLevel, context);
  }
  ~DXBundle() {
	  if(context) {
	    context->ClearState();
	    context->Flush();
	    context->Release();
	  }
	  if(device) {
	    device->Release();
	  }
  }
};

There's a couple places I could see using this, the above example is a simple one that appears fairly convenient. Automatic construction and release at the cost of a dot operator seems like a fair trade. Anyone know of any reasons to avoid creating little "construction wrappers" like this?

Note: I've left out copy and copy assign intentionally for readability, that and the jury's still out on how I want to handle them in this particular instance...

Sponsor:

#2 incertia   Crossbones+   -  Reputation: 779

Like
0Likes
Like

Posted 12 November 2012 - 09:40 PM

If it's personal code and you understand everything that is going on, then sure.

However, if other people are reading your code or if you may forget why you did it like that, then I suggest you you wrap everything in a nice class with functions that can change how you want the device to be created.
what




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS