简体   繁体   English

快速比较两个内存区域

[英]compare fast two memory regions

How to compare fast two (variable size) memory regions as binary? 如何将两个快速(可变大小)存储区域比较为二进制?

int compare (void *a,void *b,size_t size){
...
}


// reg1 > reg2
reg1 = 00001000000000000000000000000000000000000000 (binary);
reg2 = 00000100000000000000000000000000000000000000 (binary); 

if (compare(reg1,reg2,32) > 0){
  return true;
}else{
  return false;
};

All comparisons are performed using native binary because that is the internal representation, unless you need to compare the textual representation of a binary number. 所有比较都是使用本机二进制执行的,因为这是内部表示,除非您需要比较二进制数字的文本表示。

For a platform specific answer, check the assembly language for your platform's processor. 对于特定于平台的答案,请检查平台处理器的汇编语言。 Many modern processors have assembly language instructions for comparing regions of memory. 许多现代处理器具有用于比较内存区域的汇编语言指令。

As other commenters have stated, memcmp is your best choice because it should be optimized for your platform. 正如其他评论者所述, memcmp是您的最佳选择,因为应针对您的平台对其进行优化。

If you must write your own, I suggest loading a word from memory and comparing memory word by word until there is not a match. 如果您必须自己编写,我建议从内存中加载一个单词,然后逐字比较内存,直到没有匹配为止。 If you need more details, compare the words byte by byte to find where the exact difference is. 如果您需要更多详细信息,请逐字节比较单词,以找出确切的差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 比较两个包含字符串的向量的快速方法 - fast way to compare two vector containing strings 如何为STM32L475交换FLASH存储器中不同存储区的两个存储器区域? - How to swap two memory regions from different banks in FLASH Memory for STM32L475? 如何正确比较存储在内存中的两个数组? - How to properly compare two arrays stored in memory? 为什么我不能在同一分配中保留两个连续的内存区域,而不用一次调用就保留两个连续的内存区域? - Why can't I reserve two contiguous memory regions in the same allocation without reserving both with a single call? 相邻内存区域的memcpy()安全性 - memcpy() safety on adjacent memory regions Windows 7中的NUMA内存区域分配 - NUMA memory regions allocation in Windows 7 关于查询memory区域的问题(Windows) - Question on querying memory regions (Windows) 简单。 比较两个800k每个元素数组的快速方法 - Easy. Fast way to compare two 800k each elements arrays malloc():内存损坏(快速) - malloc(): memory corruption (fast) 英特尔存储故意重叠内存区域的指令 - Intel store instructions on delibrately overlapping memory regions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM