VisualAssist Key
www.board4all.biz (1-user license) Support ends 2070.9.5
00001U-JE1E81-T2NXRB-2HVFUV-JQ222N-ZEVGJZ-7DEUHD-53VZBR-A4QTYW-2J11D8-4VWBF5
www.board4all.biz (1-user license) Support ends 2070.9.5
00001U-JE1E81-T2NXRB-2HVFUV-JQ222N-ZEVGJZ-7DEUHD-53VZBR-A4QTYW-2J11D8-4VWBF5
以 nlohmann json 为例,如果你不想用多行代码释放内存,那么就用一行代码释放内存吧。
swap(*const_cast<json*>(std::addressof(static_cast<const json&>(std::move(json())))));
std::vector 例子
std::vector<int> test;
test.push_back(1);
test.swap(*const_cast<std::vector<int>*>(std::addressof(static_cast<const std::vector<int>&>(std::move(std::vector<int>())))));
static std::string SerializeChronoDate(const char* format = "%Y-%m-%d %H:%M:%S") // format = %F %T
{
char buffer[40] = {};
{
if (std::strftime(
buffer,
std::size(buffer),
format,
std::localtime(std::addressof(static_cast<const std::time_t&>(std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()))))
))
{
return std::string(buffer, std::size(buffer));
}
}
throw std::runtime_error("failed to get current date as string");
}
众所周知,LUA是最强,效率最高的脚本,但是语法也是最难用的脚本,那么接下来也就看你们个人喜好挑选一款适合自己的嵌入式脚本了。
JavaScript语法 嵌入式脚本【适合做跨平台ARM工控机、物联网等项目使用,最低要求 64KB 内存即可运行 】
https://github.com/jerryscript-project/jerryscript
https://github.com/svaarala/duktape
配到解释器 Espruino
Espruino 是一个专门为微控制器(MCU)设计的 JavaScript 解释器,最低资源开销 128KB Flash & 8KB RAM,使用 MPL-2.0 协议开源。
https://github.com/espruino/Espruino
更多介绍:https://zhuanlan.zhihu.com/p/25058124
其他语法 嵌入式脚本
https://github.com/ChaiScript/ChaiScript/
通常一般的程序员第一时间会想起用10进制转二进制,然后取某一位是否位1 实际项目中是不允许这么低效且低能的做法,那么我们可以直接使用 位与运算。来决定我们取的某一位偏移值是多少。也就是移动到二进制的某一位。 ::(真棒)
#ifndef SETBIT
# define SETBIT(x, y) (x |= (1 << y))
#endif
#ifndef GETBIT
# define GETBIT(x, y) ((x) >> (y) & 1)
#endif
if (0 == DBRead(dbnumber, start, length, static_cast<void*>(buffer)))
{
return 0 != static_cast<int32_t>(GETBIT(buffer[0], offset));
}