我最近被要求完成对于C++角色的任务,但是作为应用程序并没有决定要取得进展的任何进一步的我以为我会在这里发布一些反馈/咨询/改进/我已经忘记了概念的提醒.
任务是:
以下数据是整数值的时间序列
int timeseries[32] = {67497, 67376, 67173, 67235, 67057, 67031, 66951,
66974, 67042, 67025, 66897, 67077, 67082, 67033, 67019, 67149, 67044,
67012, 67220, 67239, 66893, 66984, 66866, 66693, 66770, 66722, 66620,
66579, 66596, 66713, 66852, 66715};
Run Code Online (Sandbox Code Playgroud)
例如,该系列可能是每天超过32天的股票收盘价.
如上所述,数据将占用32 x sizeof(int) bytes = 128 bytes
假设4字节的整数.
使用delta编码,编写要压缩的函数,以及解压缩数据的函数,如上所述.
好的,所以在此之前我从未考虑压缩,所以我的解决方案远非完美.我解决问题的方式是将整数数组压缩成一个字节数组.当将整数表示为一个字节时,我保持计算最高有效字节(msb)并将所有内容保持到这一点,同时将其余部分抛弃.然后将其添加到字节数组中.对于负值,我将msb递增1,以便在解码时通过保持前导1位值来区分正字节和负字节.
解码时,我解析这个锯齿状的字节数组,然后简单地反转压缩时执行的先前操作.如前所述,我从未在此任务之前查看压缩,因此我确实提出了自己的方法来压缩数据.我最近在看C++/Cli,之前没有真正使用它,所以决定用这种语言写它,没有特别的原因.下面是课程,最底层是单元测试.任何建议/改进/改进将非常感激.
谢谢.
array<array<Byte>^>^ CDeltaEncoding::CompressArray(array<int>^ data)
{
int temp = 0;
int original;
int size = 0;
array<int>^ tempData = gcnew array<int>(data->Length);
data->CopyTo(tempData, 0);
array<array<Byte>^>^ byteArray = gcnew array<array<Byte>^>(tempData->Length);
for (int …Run Code Online (Sandbox Code Playgroud) 我想你不能简单地用C++/CLI编译器编译C++应用程序.我想知道这是否会很困难.有没有人试过这个,如果有的话:是否需要进行大量的修改?
我在Visual C++ 2008 Professional上使用C++/CLI,因为我使用的是Windows Forms,这意味着我有托管代码而我正在尝试调用静态函数LoginAccounts,但是我得到一个错误,可能是因为我混合了使用非托管代码管理,但我无法弄清楚该做什么.我正在使用PThread for Windows
System::Void testing_Click(System::Object^ sender, System::EventArgs^ e) {
pthread_create(&t, NULL, &Contas::LoginAccounts, this); //Error in this line
}
Run Code Online (Sandbox Code Playgroud)
错误13错误C3374:除非创建委托实例,否则无法获取'Tester :: Test :: LoginAccounts'的地址
我该怎么做才能解决这个问题?这可能是一个简单的解决方案,但我无法弄清楚.提前致谢.
void LoginAccounts(){
this->btn_next->Enabled = false;
this->login_accounts->Enabled = false; //Unhandled exception here
if(this->clb_contas->CheckedItems->Count <= 0){ //Unhandled exception here
}
}
System::Void testing_Click(System::Object^ sender, System::EventArgs^ e) {
ThreadStart^ start = gcnew ThreadStart(this, &Login::LoginAccounts);
Thread^ t = gcnew Thread(start);
t->Start();
}
Run Code Online (Sandbox Code Playgroud) 我将LPCSTR转换为System :: String ^时遇到问题,但我可以将System :: String转换为带Marshal的LPCSTR.
但是我怎样才能将LPCSTR转换为System :: String ^
谢谢
public ref class masterWeapon{
public :
property int Slot {
int get(){
return 0;
}
}
masterWeapon(){
}
};
OSamp::masterWeapon mw();
int v = mw.Slot; //ERROR error C2228: left of '.Slot' must have class/struct/union
Run Code Online (Sandbox Code Playgroud)
但是下面的代码运行良好:
public ref class masterWeapon{
public :
property int Slot {
int get(){
return 0;
}
}
masterWeapon(int useless){
}
};
OSamp::masterWeapon mw(231312);
int v = mw.Slot; //works fine
Run Code Online (Sandbox Code Playgroud) 我试图从这个答案中放入类NativeBuffer 但是当windows.storage.streams.h我有很多错误,如:
Error 1 error C2872: 'AsyncStatus' : ambiguous symbol c:\program files (x86)\windows phone kits\8.0\include\abi\asyncinfo.h 75
Error 2 error C2872: 'AsyncStatus' : ambiguous symbol c:\program files (x86)\windows phone kits\8.0\include\abi\asyncinfo.h 76
Error 3 error C2872: 'AsyncStatus' : ambiguous symbol c:\program files (x86)\windows phone kits\8.0\include\abi\asyncinfo.h 77
Error 4 error C2872: 'AsyncStatus' : ambiguous symbol c:\program files (x86)\windows phone kits\8.0\include\abi\asyncinfo.h 78
Error 5 error C2371: 'IAsyncInfo' : redefinition; different basic types c:\program files (x86)\windows phone kits\8.0\include\abi\asyncinfo.h 108
Error 6 error C2872: …Run Code Online (Sandbox Code Playgroud) 有一个c ++/cli项目,它是一个Windows应用程序.在调试模式下,我们没有任何问题,但在将其带到释放模式后,此错误启动.我搜索并找到了一些论坛答案,但无法帮助我解决这个问题.
请帮我 ....
错误:
An unhandled exception of type 'System.TypeInitializationException' occurred in Unknown Module
Run Code Online (Sandbox Code Playgroud)
附加信息:" Module " 的类型初始化程序引发了异常.
我有一个C#array<System::Byte>,我希望将其转换为C++ byte*.我怎样才能做到这一点?我正在使用C++/CLR,因为它允许我在同一个项目中使用托管/非托管代码.我基本上是在编写一个DLL并制作一些可以通过C#调用的方法,但它包含非托管C++代码.
所以基本上,我的C++/CLR方法标题是这样的:
void testMethod(array<Byte>^ bytesFromCSharp);
Run Code Online (Sandbox Code Playgroud)
在其中testMethod我想将其转换bytesFromCSharp为byte*可供其他非托管C++代码使用的内容.我对byte*数组进行了malloced 并编写了一个for循环来逐字节复制,但感觉应该有一个更好的解决方案.
编辑:Hans的技术示例来自他的回答:
//C#
byte[] myBytes = {1,2,3,4};
//C++/CLI
void testMethod(array<byte>^ myBytes) {
pin_ptr<byte> thePtr = &myBytes[0];
byte* bPtr = thePtr;
nativeCode(bPtr);
...
}
Run Code Online (Sandbox Code Playgroud) 我已经管理了.net C++ dll,这是一个执行以下操作的函数:
unsigned char* mBytes = new unsigned char[hSize];
Run Code Online (Sandbox Code Playgroud)
如何在返回之前释放这个mBytes?
c++-cli ×10
c++ ×5
.net ×2
visual-c++ ×2
c# ×1
c++-cx ×1
compression ×1
lpcstr ×1
marshalling ×1
pthreads ×1
string ×1
windows ×1