c ++ memcpy读取内存

时间:2016-10-03 15:19:52

标签: c++ memcpy

我正在尝试使用memcpy来读取内存。

BYTE test[] = {0x01};
BYTE test2[] = {0x00};
memcpy (test, test2, sizeof(test));
if (test == test2){
    MessageBox::Show("Same");
}else{
    MessageBox::Show("Different");
}

为什么测试和测试2总是不同?

感谢您的帮助。

3 个答案:

答案 0 :(得分:3)

您正在比较import { Component } from '@angular/core'; import { Platform } from 'ionic-angular'; import { StatusBar } from 'ionic-native'; import { TabsPage } from '../pages/tabs/tabs'; @Component({ template: `<ion-nav [root]="rootPage"></ion-nav>` }) export class MyApp { rootPage = TabsPage; constructor(platform: Platform) { platform.ready().then(() => { // Okay, so the platform is ready and our plugins are available. // Here you can do any higher level native things you might need. StatusBar.styleDefault(); platform.registerBackButtonAction(()=>{ //how do i handle back button },600) }); } } memcmp的地址。请改用test

您的代码等同于

test2

将其更改为

memcmp

应该按预期工作。

答案 1 :(得分:0)

因为您正在测试数组地址的相等性。请尝试使用override func layoutSubviews() { super.layoutSubviews() let ev = UIView(frame: self.bounds) ev.backgroundColor = UIColor.blueColor() ev.translatesAutoresizingMaskIntoConstraints = false self.addSubview(ev) ev.rightAnchor.constraintEqualToAnchor(self.rightAnchor).active = true ev.bottomAnchor.constraintEqualToAnchor(self.bottomAnchor).active = true ev.leftAnchor.constraintEqualToAnchor(self.leftAnchor).active = true ev.heightAnchor.constraintEqualToAnchor(self.heightAnchor, multiplier: 1.5).active = true let myPath: CGPathRef = PocketSVG.pathFromSVGFileNamed("CategoriesBar").takeUnretainedValue() //Creating a CGPath object using a 3rd party API var transform: CGAffineTransform = CGAffineTransformMakeScale(self.frame.size.width / 754.0, self.frame.size.height / 220.0) //Resizing it let transformedPath: CGPathRef = CGPathCreateMutableCopyByTransformingPath(myPath, &transform)! //Creating a re-sized CGPath let myShapeLayer = CAShapeLayer() myShapeLayer.path = transformedPath myShapeLayer.fillRule = kCAFillRuleEvenOdd let myMaskedView = UIView(frame: self.frame) myMaskedView.backgroundColor = UIColor.blackColor() myMaskedView.layer.mask = myShapeLayer ev.maskView = myMaskedView //THE PROBLEM. If I remove this line the view is visible (but it isn’t masked), but when I don’t the view just completely disappears! }

答案 2 :(得分:0)

当数组的名称本身使用时,它会变成一个指针,所以你要比较两个数组的地址,而不是它们的内容。