Using pointer to access array instead of index

Posted 荷树栋

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Using pointer to access array instead of index相关的知识,希望对你有一定的参考价值。

see MSP430 coding example below.

   uint8_t parity = 0;
   uint8_t index = 0;
   //flag
   gMUXTask.responseData[index++] = MUX_DATA_BIT_LOW;
   //dirty
   gMUXTask.responseData[index++] = gDeviceStatus.responseStatus.dirty;
   parity += gDeviceStatus.responseStatus.dirty;
   //smoke alarm
   gMUXTask.responseData[index++] = gDeviceStatus.responseStatus.smokeAlarm;
   parity += gDeviceStatus.responseStatus.smokeAlarm;
   //high temperature
   gMUXTask.responseData[index++] = gDeviceStatus.responseStatus.highTemperature;
   parity += gDeviceStatus.responseStatus.highTemperature;
   //low temperature
   gMUXTask.responseData[index++] = gDeviceStatus.responseStatus.lowTemperature;
   parity += gDeviceStatus.responseStatus.lowTemperature;
   //miss Head
   gMUXTask.responseData[index++] = gDeviceStatus.responseStatus.missHead;
   parity += gDeviceStatus.responseStatus.missHead;
   //parity
   gMUXTask.responseData[index++] = CalcParity(isOddAlgorithm(false), parity);
   //outputState
   gMUXTask.responseData[index++] = MUX_DATA_BIT_LOW;

The ASM code generated is below, it is around 120bytes.

Another example here,

   uint8_t* p = gMUXTask.responseData;
   *p++ = MUX_DATA_BIT_LOW;
   //dirty
   *p++ = gDeviceStatus.responseStatus.dirty;
   parity += gDeviceStatus.responseStatus.dirty;
   //smoke alarm
   *p++ = gDeviceStatus.responseStatus.smokeAlarm;
   parity += gDeviceStatus.responseStatus.smokeAlarm;
   //high temperature
   *p++ = gDeviceStatus.responseStatus.highTemperature;
   parity += gDeviceStatus.responseStatus.highTemperature;
   //low temperature
   *p++ = gDeviceStatus.responseStatus.lowTemperature;
   parity += gDeviceStatus.responseStatus.lowTemperature;
   //miss Head
   *p++ = gDeviceStatus.responseStatus.missHead;
   parity += gDeviceStatus.responseStatus.missHead;
   //parity
   *p++ = CalcParity(isOddAlgorithm(false), parity);
   //outputState
   *p++ = MUX_DATA_BIT_LOW;

The ASM code generated, it is about 106 bytes.

Using pointer to access an array which has a better performance.

以上是关于Using pointer to access array instead of index的主要内容,如果未能解决你的问题,请参考以下文章

How to CORS enable ArcGIS Server 10.2.1 to Access REST Services without Using proxy.ashx

mysql启动提示 access denied for user root@localhost(using password:YES)

Failed to set session cookie. Maybe you are using HTTP instead of HTTPS to access phpMyAdmin.

Cloning failed using an ssh key for authentication, enter your GitHub credentials to access private

You may experience an access violation when you access an STL object through a pointer or reference

错误代码: 1045 Access denied for user 'skyusers'@'%' (using password: YE