Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


gdunbar

Member Since 22 Feb 2006
Offline Last Active Today, 07:28 AM

#5168350 How dangerous is returning a initialized pointer in C++?

Posted by gdunbar on 22 July 2014 - 06:07 AM

All the discussion about smart pointers is great. However, it is possible to make the original code safe (or safer) without using smart pointers. You need to use a static function for Create, instead of a standard function. A static function is part of the class, but doesn't access any of the class members, and thus is safe to use even if you don't have an instantiated object. So, change:

EngineAPI *Create();

To:

static EngineAPI *Create();

And change:

gEngine = gEngine->Create();

To:

gEngine = EngineAPI::Create();

Again, all the smart pointer and ownership discussion is great, but static Create functions are a pattern you'll often see, and are perfectly valid.

 

Geoff




#5139766 Removing Large number of objects from vector immediately.

Posted by gdunbar on 17 March 2014 - 12:39 PM

How have you profiled this code? I suspect that the "delete list1;" call might be pretty quick compared to the allocations and push_back() calls (which will dynamically resize your vector). First step is to verify that the slow part is actually what you think it is.

 

Second step is to be sure you are using a non-debug build, as allocations and deletes can be significantly slower with debug builds.

 

If you are using Visual Studio, be sure to turn off the STL debugging stuff, too, as that can be frightfully slow.

 

OK, if all of that doesn't help (and I think it will), the big optimization I can think of is to move away from std::vector and use the C-style array allocation mechanism directly. Then you can allocate and free a while bunch of objects at once. This is not nearly as maintainable, though, so be sure to exhaust other possibilities first.

 

Hmm... an object pool could work too. Also to be avoided if possible.

 

Good luck!

Geoff




#5000997 Virtual still the bad way ?

Posted by gdunbar on 14 November 2012 - 02:03 PM

Virtual functions are the bedrock of modern, object-oriented C++, and are unlikely to be a significant performance bottleneck on today's relatively fast processors. I recommend you proceed with using them. If at some point in the future, as a result of performance profiling, you do identify a virtual function or two that are slowing your code down (perhaps used very often in a tight loop), then address the problem locally at that time.

Good luck!
Geoff


#4957634 Seeking in Direct Show

Posted by gdunbar on 10 July 2012 - 09:54 AM

No, that's not what you want at all. You aren't writing your own filter, just using existing filters.

The documentation isn't great, but this topic "Seeking the Filter Graph" should help:

http://msdn.microsoft.com/en-us/library/windows/desktop/dd377561(v=vs.85).aspx

It's the IMediaSeeking interface that you want.

Good luck!
Geoff


PARTNERS