如果mem是共享内存位置,我是否需要:
XCHG EAX,mem
Run Code Online (Sandbox Code Playgroud)
要么:
LOCK XCHG EAX,mem
Run Code Online (Sandbox Code Playgroud)
原子地进行交换?
谷歌搜索这会产生是和否答案.有没有人知道这个?
所以,我需要一些帮助.我正在用C++开发一个项目.但是,我想我已经设法破坏了我的堆.这是基于我std::string向一个类添加了一个并从另一个类中赋值的事实std::string:
std::string hello = "Hello, world.\n";
/* exampleString = "Hello, world.\n" would work fine. */
exampleString = hello;
Run Code Online (Sandbox Code Playgroud)
使用堆栈转储在我的系统上崩溃.所以基本上我需要停下来查看我的所有代码和内存管理内容,找出我搞砸了的地方.代码库仍然很小(约1000行),因此这很容易实现.
不过,我对这种东西感到头疼,所以我想我会把它扔出去.我在一个Linux系统上并且已经四处乱窜valgrind,虽然我不知道我在做什么,但它确实报告说它std::string的析构函数是无效的.我不得不承认从谷歌搜索中获得"堆腐败"一词; 关于这类东西的任何通用文章也将受到赞赏.
(之前rm -rf ProjectDir,在C#再做一次:D)
编辑:我还没有说清楚,但我要求的是诊断这些记忆问题的建议.我知道std :: string的内容是正确的,所以这是我做过的事情(或者是一个bug,但是选择不是问题).我确信我可以查看我编写的代码,你很聪明的人会立即看到问题,但我想将这种代码分析添加到我的'工具箱'中,就像它一样.
只是看看在python中获取命名常量的方法.
class constant_list:
(A_CONSTANT, B_CONSTANT, C_CONSTANT) = range(3)
Run Code Online (Sandbox Code Playgroud)
那么当然你可以像这样引用它:
constant_list.A_CONSTANT
Run Code Online (Sandbox Code Playgroud)
我想你可以使用字典,使用字符串:
constant_dic = {
"A_CONSTANT" : 1,
"B_CONSTANT" : 2,
"C_CONSTANT" : 3,}
Run Code Online (Sandbox Code Playgroud)
并像这样引用它:
constant_dic["A_CONSTANT"]
Run Code Online (Sandbox Code Playgroud)
那么,我的问题很简单.有没有更好的方法呢?不是说这些不足或什么,只是好奇 - 我错过了任何其他常见的习语吗?
提前致谢.
我想解析配置文件sorta的事情,如下:
[KEY:Value]
[SUBKEY:SubValue]
Run Code Online (Sandbox Code Playgroud)
现在我开始使用a StreamReader,将线转换为字符数组,当我认为必须有更好的方法时.所以我请谦虚的读者帮助我.
一个限制是它必须在Linux/Mono环境中工作(确切地说是1.2.6).我没有最新的2.0版本(Mono),因此请尝试将语言功能限制为C#2.0或C#1.0.
给出这样的声明:
class A {
public:
void Foo() const;
};
Run Code Online (Sandbox Code Playgroud)
这是什么意思?
谷歌出现了这个:
如果成员函数可以在const(this)对象上操作,则应在其后面使用const关键字声明它们.如果函数未声明为const,则无法应用于const对象,并且编译器将给出错误消息.
但我发现有点令人困惑; 任何人都可以用更好的条件吗?
谢谢.
我正在运行autoconf并将SHELL设置为'/ bin/sh'.这造成了巨大的问题.如何强制SHELL成为autoconf的'/ bin/bash'?
我正试图在osx上运行它,它正在使用linux.Linux正在使用SHELL =/bin/bash.osx默认为/ bin/sh.
这有点奇怪,但今天我正在寻找GNU汇编程序(我希望能够至少阅读语法),并且试图让我的这个有点人为的例子工作.也就是说我只想从0到100,一直打印数字.几分钟后,我想出了这个:
# count.s: print the numbers from 0 to 100.
.text
string: .asciz "%d\n"
.globl _main
_main:
movl $0, %eax # The starting point/current value.
movl $100, %ebx # The ending point.
_loop:
# Display the current value.
pushl %eax
pushl $string
call _printf
addl $8, %esp
# Check against the ending value.
cmpl %eax, %ebx
je _end
# Increment the current value.
incl %eax
jmp _loop
_end:
Run Code Online (Sandbox Code Playgroud)
我从中得到的只是一遍又一遍地打印出来.就像我说的,只是一个有点人为的例子,所以不要太担心它,这不是生死攸关的问题.
(格式有点混乱,但没什么大不了的).
所以我有一个JPanel实现MouseListener和MouseMotionListener:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DisplayArea extends JPanel implements MouseListener, MouseMotionListener {
public DisplayArea(Rectangle bounds, Display display) {
setLayout(null);
setBounds(bounds);
setOpaque(false);
setPreferredSize(new Dimension(bounds.width, bounds.height));
this.display = display;
}
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
if (display.getControlPanel().Antialiasing()) {
g2.addRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
}
g2.setColor(Color.white);
g2.fillRect(0, 0, getWidth(), getHeight());
}
public void mousePressed(MouseEvent event) {
System.out.println("mousePressed()");
mx1 = event.getX();
my1 = event.getY();
}
public void mouseReleased(MouseEvent event) {
System.out.println("mouseReleased()");
mx2 …Run Code Online (Sandbox Code Playgroud) 我正在使用Glade 3为我正在研究的PyGTK应用程序创建一个GtkBuilder文件.这是用于管理带宽,所以我有一个gtk.ComboBox用于选择要跟踪的网络接口.
如何在运行时向ComboBox添加字符串?这是我到目前为止:
self.tracked_interface = builder.get_object("tracked_interface")
self.iface_list_store = gtk.ListStore(gobject.TYPE_STRING)
self.iface_list_store.append(["hello, "])
self.iface_list_store.append(["world."])
self.tracked_interface.set_model(self.iface_list_store)
self.tracked_interface.set_active(0)
Run Code Online (Sandbox Code Playgroud)
但是ComboBox仍然是空的.我尝试过RTFM,但是如果有的话,就会更加困惑.
干杯.
这是使用的代码GetOpenFileNameW:
import core.sys.windows.windows;
import std.stdio, std.string, std.utf;
pragma(lib, "comdlg32");
// Fill in some missing holes in core.sys.windows.windows.
extern (Windows) DWORD CommDlgExtendedError();
enum OFN_FILEMUSTEXIST = 0x001000;
void main()
{
auto buf = new wchar[1024];
OPENFILENAMEW ofn;
ofn.lStructSize = ofn.sizeof;
ofn.lpstrFile = buf.ptr;
ofn.nMaxFile = buf.length;
ofn.lpstrInitialDir = null;
ofn.Flags = OFN_FILEMUSTEXIST;
BOOL retval = GetOpenFileNameW(&ofn);
if (retval == 0) {
// Get 0x3002 for W and 0x0002 for A. ( http://msdn.microsoft.com/en-us/library/windows/desktop/ms646916(v=vs.85).aspx )
throw new Exception(format("GetOpenFileName failure: 0x%04X.", CommDlgExtendedError()));
} …Run Code Online (Sandbox Code Playgroud)