Objective-C++内存问题

发布于 2024-08-20 10:09:52 字数 1485 浏览 3 评论 0原文

我有记忆障碍。

我有一个 C++ 库(Eyescale 的均衡器),他们使用 Traversal 访问者模式允许您向其类添加新功能。

我终于弄清楚它是如何工作的,并且我有一个访客 返回对象之一的属性。 (因为我不知道如何 他们被分配了)。

所以。

我的小代码是这样做的:

VisitorResult AGLContextVisitor::visit( Channel* channel ) 
{ 
  // Search through Nodes, Pipes until we get to the right window. 
  // Add some code to make sure we find the right one? 

  // Not executing the following code as C++ in gdb? 
  eq::Window* w = channel->getWindow(); 
  OSWindow* osw = w->getOSWindow(); 
  AGLWindow* aw = (AGLWindow *)osw; 
  AGLContext agl_ctx = aw->getAGLContext(); 
  this->setContext(agl_ctx); 

  return TRAVERSE_PRUNE; 
} 

所以这就是问题所在。

eq::Window* w = channel->getWindow(); 
(gdb) print w 
0x0 

但是如果我这样做:

(gdb) set objc-non-blocking-mode off 
(gdb) print w=channel->getWindow() 
0x300effb9 

// 一个诚实的内存位置,并将 w 设置为在调试器窗口中验证 XCode 的。

它对 osw 做同样的事情。

我不明白。为什么有些东西在(gdb)中可以工作,但在代码中却不起作用?

该文件完全是一个cpp文件,但是好像是在objc++中运行的, 因为我需要关闭阻止。

帮助!?我觉得我在这里缺少一些内存管理的基本知识, 使用 C++ 或 Obj-C。

[编辑]

channel->getWindow() 应该这样做:

/** @return the parent window. @version 1.0 */
Window* getWindow() { return _window; }

如果我从纯 C++ 应用程序运行代码,代码也可以正常执行。

[编辑]

不...我尝试创建一个简单的独立程序,因为我厌倦了将其作为插件运行。调试起来很混乱。

不,它也不在 C++ 程序中运行。所以我真的对自己做错了什么感到不知所措。

谢谢,

- 史蒂芬·弗拉尼

I'm having memory woes.

I've got a C++ Library (Equalizer from Eyescale) and they use the Traversal
Visitor Pattern to allow you to add new functionality to their classes.

I've finally figured out how it works, and I've got a Visitor that just
returns the properties from one of the objects. (since I don't know how
they're allocated).

so.

My little code does this:

VisitorResult AGLContextVisitor::visit( Channel* channel ) 
{ 
  // Search through Nodes, Pipes until we get to the right window. 
  // Add some code to make sure we find the right one? 

  // Not executing the following code as C++ in gdb? 
  eq::Window* w = channel->getWindow(); 
  OSWindow* osw = w->getOSWindow(); 
  AGLWindow* aw = (AGLWindow *)osw; 
  AGLContext agl_ctx = aw->getAGLContext(); 
  this->setContext(agl_ctx); 

  return TRAVERSE_PRUNE; 
} 

So here's the problem.

eq::Window* w = channel->getWindow(); 
(gdb) print w 
0x0 

BUT If I do this:

(gdb) set objc-non-blocking-mode off 
(gdb) print w=channel->getWindow() 
0x300effb9 

// an honest memory location, and sets w as verified in the Debugger window
of XCode.

It does the same thing for osw.

I don't get it. Why would something work in (gdb) but not in the code?

The file is completely a cpp file, but it seems to be running in objc++,
since I need to turn blocking off.

Help!? I feel like I'm missing some memory-management basic thing here,
either with C++ or Obj-C.

[edit]

channel->getWindow() is supposed to do this:

/** @return the parent window. @version 1.0 */
Window* getWindow() { return _window; }

The code also executes fine if I run it from a C++-only application.

[edit]

No... I tried creating a simple stand-alone program since I was tired of running it as a plugin. Messy to debug.

And no, it doesn't run in the C++ program either. So I'm really at a loss as to what I'm doing wrong.

Thanks,

--
Stephen Furlani

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

◇流星雨 2024-08-27 10:09:52

我想我应该回答并结束这个问题。

我使用的方法是完全线程不安全的。我跨线程调用,Carbon/Cocoa,C++/ObjC。

不用说,永远不要这样做!我经历了惨痛的教训。

-史蒂芬

I suppose I should answer and close this out.

The methods I was using were completely thread-unsafe. I was calling out across threads, Carbon/Cocoa, C++/ObjC.

Needless to say, don't ever do that! I learned the hard way.

-Stephen

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文