diff --git a/docs/basic_coding/utils/crc.md b/docs/basic_coding/utils/crc.md index 3e0135e..675d305 100644 --- a/docs/basic_coding/utils/crc.md +++ b/docs/basic_coding/utils/crc.md @@ -14,13 +14,12 @@ sidebar_position: 8 #include "crc.hpp" uint8_t packet[5]{1, 2, 3, 4, 0}; -LibXR::CRC8::GenerateTable(); packet[4] = LibXR::CRC8::Calculate(packet, 4); bool valid = LibXR::CRC8::Verify(packet, sizeof(packet)); ``` -查找表也可以在首次计算时生成。多个上下文可能同时首次使用同一 CRC 类时,初始化阶段先调用 `GenerateTable()`。 +查找表在编译期生成,存放在只读数据段,使用前不需要初始化,多个线程或中断同时首次调用也不会互相干扰。查找表可以通过各类的 `tab_` 读取,类型是 `std::array`。 ## 参数 diff --git a/i18n/en/docusaurus-plugin-content-docs/current/basic_coding/utils/crc.md b/i18n/en/docusaurus-plugin-content-docs/current/basic_coding/utils/crc.md index 177b312..2f7b423 100644 --- a/i18n/en/docusaurus-plugin-content-docs/current/basic_coding/utils/crc.md +++ b/i18n/en/docusaurus-plugin-content-docs/current/basic_coding/utils/crc.md @@ -14,13 +14,12 @@ sidebar_position: 8 #include "crc.hpp" uint8_t packet[5]{1, 2, 3, 4, 0}; -LibXR::CRC8::GenerateTable(); packet[4] = LibXR::CRC8::Calculate(packet, 4); bool valid = LibXR::CRC8::Verify(packet, sizeof(packet)); ``` -Tables are also generated lazily on first calculation. If several contexts can race the first use of one CRC class, generate its table during initialization. +The lookup tables are built at compile time and kept in read-only data. They need no initialization before use, and several threads or interrupts may make the first call at the same time. Each class exposes its table as `tab_`, a `std::array`. ## Parameters