我有以下课程:
class A
{
public:
B& getB() {return b;}
private:
B b;
};
class B
{
~B() {cout<<"destructor B is called";}
...
};
void func()
{
A *a = new a;
B b = a->getB();
.....
}
Run Code Online (Sandbox Code Playgroud)
为什么退出函数func时会调用B类的析构函数?Doest函数getB返回对象B的referance?如果类A仍然存在于函数func的末尾,为什么B的析构函数被调用?
我正在 C++ 中创建两个数组,它们将在 java 端读取:
env->NewDirectByteBuffer
env->NewByteArray
Run Code Online (Sandbox Code Playgroud)
这些函数会复制我发送的缓冲区吗?我需要在 C++ 端的堆上创建缓冲区还是可以在堆栈上创建它因为 jvm 会复制它?
例如,此代码是否可以正常运行:
std::string stam = "12345";
const char *buff = stam.c_str();
jobject directBuff = env->NewDirectByteBuffer((void*)buff, (jlong) stam.length() );
Run Code Online (Sandbox Code Playgroud)
另一个例子:
std::string md5 "12345";
jbyteArray md5ByteArray = env->NewByteArray((jsize) (md5.length()));
env->SetByteArrayRegion(md5ByteArray, 0, (jsize) (md5.length()), (jbyte*)
md5.c_str());
Run Code Online (Sandbox Code Playgroud)
字符串在堆栈上创建。这段代码会一直工作还是我需要在堆上创建这些字符串并负责在 java 使用完后删除它
我使用inotify来监视某些文件的更改.问题是inotify_event event-> name是空的,所以我不能告诉哪个文件被修改了
为什么event-> name为空?
fd = inotify_init();
wd = inotify_add_watch (m_fd, "/tmp/myfile", IN_MODIFY | IN_CREATE | IN_DELETE);
wd1 = inotify_add_watch (m_fd, "/tmp/myfile2", IN_MODIFY | IN_CREATE | IN_DELETE);
-----
unsigned char buffer[BUFFER_SIZE];
ssize_t len = ACE_OS::read(fd, buffer, sizeof(buffer));
ssize_t i = 0;
while (i < len)
{
inotify_event *event = ( struct inotify_event * ) &buffer[ i ];
i += EVENT_SIZE + event->len;
}
Run Code Online (Sandbox Code Playgroud) 获取数据库中创建的分区数量的最有效方法是什么?我正在使用*postgresq*l APi for c ++.
c++ ×2
destructor ×1
inheritance ×1
inotify ×1
java ×1
native ×1
postgresql ×1
reference ×1
sql ×1