我从Kinect输出的图像中选择了4个点,因此每个点都有其(x, y, z)坐标.
我的目标是确定4点是否落在同一平面上.
这是我的功能:
public bool isValidPlane()
{
for (int i = 0; i < edgesPoints.Length; i++)
{
double absPlaneEquation = Math.Abs(distance -
(normal.X * edgesPoints[i].X + normal.Y * edgesPoints[i].Y + normal.Z * edgesPoints[i].Z));
if (absPlaneEquation > 1500) /* 1500 is a tolerance error*/
{
return false;
}
}
return true;
}
Run Code Online (Sandbox Code Playgroud)
这normal也是法线(平面上2个向量的交叉乘积,之前已经从4个选定点中的3个计算得到)到平面并且它被标准化:
private void calcPlaneNormalVector()
{
if (lastEdgeNumber < 3)
{
return;
}
Vector3D vec1 = new Vector3D(edgesPoints[0], edgesPoints[1]);
Vector3D vec2 = new Vector3D(edgesPoints[0], …Run Code Online (Sandbox Code Playgroud) 我碰到了这个问题,这个关于在Linux中删除打开的文件的问题
但是,我仍然感到困惑的是,当一个进程(称为它A)删除另一个进程打开的文件时,RAM中发生了什么B。
这让我感到困惑(我的分析可能是错误的,如果是,请纠正我):
inode,因此,该文件已从GFDT中删除。inode对此。问题是,为什么“已删除”文件仍可以由打开它的进程访问?而如何是被操作系统做了什么?
编辑通过UFDT我的意思是保持其打开的过程的文件的文件描述符进程的文件描述符表(每个进程都有自己的UFDT)和GFDT是全球文件描述符表,只有一个GFDT在系统(本例中为RAM)。
在c ++ 11标准中,如果B类继承自A类,那么'B是A'.但是,我仍然对这个概念感到困惑:看看这段代码:
class Base {
public:
virtual ~Base() {}
virtual Base* clone() const = 0;
};
class Derived : public Base {
public:
virtual Base* clone() const {
return new Derived(*this);
}
//<more functions>
};
Run Code Online (Sandbox Code Playgroud)
我们从Derived返回了指向Base的指针,但是如果在此代码中使用此方法:
Derived* d1 = new Derived();
Derived* d2 = d1->clone();
Run Code Online (Sandbox Code Playgroud)
我们所做的是分配Base*在Derived*!
问题:
为什么这段代码不能编译?为了适应继承,它怎么能被修改(以及为什么?)?
我正在学习在C#中使用任务并行库(TPL),并编写了以下代码(您可以复制它并运行它).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace parallelTaskLibrary
{
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 6; i++)
{
var t01 = Task.Factory.StartNew(() => Console.WriteLine("in loop: i = {0}", i));
}
Console.WriteLine("press any key to terminate...");
Console.ReadKey();
}
}
}
Run Code Online (Sandbox Code Playgroud)
在for循环中,计数器索引i无法启动值为的迭代i = 6.但是,我得到的输出是这样的:
press any key to terminate...
in loop: i = 6
in loop: i = 6
in …Run Code Online (Sandbox Code Playgroud) 我是 ML 的新手,这是我尝试编写一个接收的函数:
该函数应返回strin的出现次数L
这是我的代码:
(*
* return number of occurences of str in L
* count should be initialized to zero.
*)
fun aux_num_of_occur(L: string list) (str:string) (count:int) =
if null L then 0
else if str = hd(L) then
aux_num_of_occur tl(L) str (count+1)
else
aux_num_of_occur tl(L) str count
Run Code Online (Sandbox Code Playgroud)
这些是我得到的错误:
Error: case object and rules don't agree [tycon mismatch]
rule domain: string list * string * int
object: ('Z list -> 'Z …Run Code Online (Sandbox Code Playgroud) 我已经读过使用malloc()时的规则总是匹配free().如果在程序中使用malloc()7次,则必须有相应数量的free()s.但是,这似乎不适用于几个char*我在一个结构中的malloc.结构:
typedef struct
{
char* ID;
char* PassWord;
}Account, *pAccount, **ppAccount;
typedef struct
{
unsigned int numAccounts;
ppAccount accounts;
}Collection,*pAccountCollection;
Run Code Online (Sandbox Code Playgroud)
mallocs(功能简化):
void AddNewAccount(pAccountCollection e){
int string_length = sizeof(char)*26;
pAccount newAct = malloc(sizeof(Account));
newAct->ID = malloc(string_length);
newAct->PassWord = malloc(string_length);
e ->numAccounts++;
e->accounts[e->numAccounts-1] = newAct;
}
Run Code Online (Sandbox Code Playgroud)
最后,最后调用清理:
void CleanUp(pAccountCollection e){
unsigned int i;
if(e->numAccounts != 0){
for (i = 0; i < e->numAccounts; i++){
free(e->accounts[i]->ID);
free(e->accounts[i]->PassWord);
free(e->accounts[i]);
}
free(e->accounts);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在检查泄漏
_CrtDumpMemoryLeaks();
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
Run Code Online (Sandbox Code Playgroud)
并且它标记了newAct的ID和PassWord,因为没有释放26个字节.
Detected memory leaks!
Dumping objects ->
{73} …Run Code Online (Sandbox Code Playgroud) 我在C中有这个代码:
char* func(char* str, int a) {
str = malloc(a * sizeof(char));
return str;
}
int main() {
char* s1 = NULL;
s1 = func(s1,4);
s1 = "123";
free(s1);
s1 = func(s1, 5);
s1 = "1234";
free(s1);
...
}
Run Code Online (Sandbox Code Playgroud)
我一直得到运行时错误(好像它是一个infinte循环)
这是使用s1在main()合法的吗?它会产生内存泄漏吗?
我试图理解如何将函数定义为friend function影响其在内存(RAM)中的位置.
例如,每个类都有一个包含其所有方法和函数的表.此外,虚拟功能放在vtable.
friend功能在哪里?
我担心的原因是由于[递归]函数已经通过我的c ++代码中的多个线程调用了很多次,最终我得到了"v'table腐败运行时异常".这是内存损坏的标志(正如我在这里看到的那样).
此外,当将此函数声明为常规的类外函数时,异常仍然存在.
friend然而,当声明该功能时(这是一个糟糕的设计,但为了实验),该异常不再弹出.
因此,我的问题是关于朋友功能的记忆位置.