• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Thousands of leaked CGContext ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Thousands of leaked CGContext ?


  • Subject: Re: Thousands of leaked CGContext ?
  • From: Uli Kusterer <email@hidden>
  • Date: Mon, 20 Apr 2015 17:51:12 +0200

On 20 Apr 2015, at 09:05, Eric Matecki <email@hidden> wrote:
>>>    CGDataProviderRef  provider = CGDataProviderCreateDirect( &mps, sizeof(mps), &callbacks );
>>>
>>>    NSWindow*  window = (NSWindow*)Window();
>>
>> What does this line do?
>
> It's just a global function which returns the (only) window.
> For crossplatform compatibility reasons (our app runs on MacOSX, Linux, Windows and Android) it returns a void*,
> that's why the cast is needed.

 Not sure if you know this, but there are many tricks to let you avoid casts like this. For one, you can typedef the type, so the cross-platform code can assume a return type named CrossPlatformWindowPtr and platform-specific code sees a platform-specific type anyway:

#if __OBJC__
#import <Cocoa/Cocoa.h>
typedef NSWindow *CrossPlatformWindow;
#else
typedef struct NSWindow  *CrossPlatformWindow;
#endif

This will produce the same name-mangling in C++ on Mac and iOS, and since both are pointers they're the identical size, but the second compiles in C and C++-only files. It also means that all ObjC source code can just use it as the NSWindow it is, taking advantage of what little type checking Objective-C offers, at least. And no accidental hidden bugs by casting a CrossPlatformButton to a CrossPlatformWindow by accident.

And the Windows versions could just have a simple

typedef HWND CrossPlatformWindow;

or whatever would be appropriate there. If you're curious about more safe and practical C++ tricks, I spent almost an hour talking about a lot of C++ on Andrew Pontious' Edge Cases podcast once: http://edgecasesshow.com/017-then-youre-just-writing-cplusplus.html <http://edgecasesshow.com/017-then-youre-just-writing-cplusplus.html>

-- Uli
http://stacksmith <http://stacksmith/>.org/
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >Thousands of leaked CGContext ? (From: Eric Matecki <email@hidden>)
 >Re: Thousands of leaked CGContext ? (From: David Duncan <email@hidden>)
 >Re: Thousands of leaked CGContext ? (From: Eric Matecki <email@hidden>)

  • Prev by Date: Re: UIAlertView has zero bounds
  • Next by Date: Re: UIAlertView has zero bounds
  • Previous by thread: Re: Thousands of leaked CGContext ?
  • Next by thread: Re: Thousands of leaked CGContext ?
  • Index(es):
    • Date
    • Thread