Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: extend dynamically allocated evidence array by additionalCapacity #59

Merged
merged 6 commits into from
Oct 30, 2024

Conversation

justadreamer
Copy link
Contributor

in case derived evidence is to be added on the fly during device detection (f.e. derived from 51d_gethighentropyvalues)

in case derived evidence is to be added on the fly during device detection (f.e. derived from 51d_gethighentropyvalues)
@justadreamer
Copy link
Contributor Author

decision is to make an additional array to hold extra evidence, rather than instruct on the call site

jwrosewell and others added 4 commits October 29, 2024 10:11
… going to be exceeded when new evidence is added a new array is created and linked to the original one. This is needed to avoid situations where GHEV or other dynamic evidence is unpacked and there is insufficient capacity in the original evidence array. The developer would receive unpredicatable results and it would not be obvious where the problem is. The dynamic allocation of more memory for evidence can be avoided by specifying a sufficiently large evidence capacity when the initial evidence array is created.

The void pointer used in pairs and evidence pairs has been removed and the KeyValuePair with character pointers used throughout. This reduces problems with casting void pointers for no reason.
The evidence key value pair now uses the key value pair to reduce duplication and ensure that all strings have length fields to reduce calls to strlen and to handle GHEV evidence where the string may not be null terminated. Code that expects the keys, values, or parsed value to be null terminated now needs to use the length field to get the number of characters. If a null terminated version is needed then the caller will need to make a copy and add a null terminator.
… this now that evidence can be expanded dynamically.
@justadreamer
Copy link
Contributor Author

justadreamer commented Oct 29, 2024

The implementation works for me, there was a minor check added to EvidenceFree. The tests that use this from the DD side are passing.

Two considerations:

  1. Perhaps it would be simpler to use realloc instead of managing linked lists. It can also turn out to be more performant. With realloc there is a high chance of not having to do any new allocations, with linked lists - we are guaranteed to do new allocations. Given evidence arrays are mainly structs with pointers (not raw string buffers) - realloc will extend the already allocated available region of memory and reuse the same pointer and not have to actually allocate and move anything - in that case it is constant time - that should be the behavior in the majority of cases. Move occurs only worst case if a contiguous region of memory is not available in the same memory location - and it has to allocate a new one, but copying in this case would also be quite quick as each element in the evidence array is just several numbers (string pointers and lengths). Strings themselves are not moved. We would need to have FIFTYONE_DEGREES_ARRAY_REALLOC macro and underlying MemoryTrackingRealloc, MemoryStandardRealloc that would call standard realloc inside.

  2. If we don't provide the capacity parameter to init EvidenceBase - we don't let the users of higher-level languages hint the capacity needed for the expanded evidence array, so by default it will always be creating tight evidence arrays and we the underlying code will always have to add capacity either through linked lists or realloc. Perhaps that feature may still be provided for some use cases requiring high performance to not have reallocate, however with realloc it likely won't be needed...

@jwrosewell
Copy link
Contributor

Re: Realloc - It is more important to make the feature available than add new memory management code for a fringe case. We can consider realloc support in version 5.
Re: EvidenceBase - a new method could be added which provides the dataset that the evidence will be used with so that the dataset can be used to inform the capacity of the C evidence instance returned. We can consider this if we see issues with higher level languages. Generally the overhead of marshaling the data is likely to be greater than using a linked list of lists.

Copy link

Unit Tests - Mac_x64_Debug

518 tests   518 ✅  6s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit 071b5a7.

Copy link

Unit Tests - Ubuntu_x64_Debug

520 tests   520 ✅  4s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit 071b5a7.

Copy link

Integration Tests - Mac_x64_Debug

0 tests   0 ✅  0s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 071b5a7.

Copy link

Unit Tests - Ubuntu_x86_Debug

520 tests   520 ✅  5s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit 071b5a7.

Copy link

Integration Tests - Ubuntu_x64_Debug

0 tests   0 ✅  0s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 071b5a7.

Copy link

Unit Tests - Ubuntu_x86_Release

520 tests   520 ✅  2s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit 071b5a7.

Copy link

Integration Tests - Ubuntu_x86_Debug

0 tests   0 ✅  0s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 071b5a7.

Copy link

Integration Tests - Ubuntu_x86_Release

0 tests   0 ✅  0s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 071b5a7.

Copy link

Unit Tests - Ubuntu_x64_Release

520 tests   520 ✅  2s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit 071b5a7.

Copy link

Performance Tests - Ubuntu_x86_Release

0 tests   0 ✅  0s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 071b5a7.

Copy link

Integration Tests - Ubuntu_x64_Release

0 tests   0 ✅  0s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 071b5a7.

Copy link

Performance Tests - Ubuntu_x64_Release

0 tests   0 ✅  0s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 071b5a7.

Copy link

github-actions bot commented Oct 30, 2024

Unit Tests - Windows_VS_x86_Release

498 tests   498 ✅  4s ⏱️
 69 suites    0 💤
  1 files      0 ❌

Results for commit 54d8c7f.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Oct 30, 2024

Unit Tests - Windows_x86_Debug

520 tests   520 ✅  14s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit 54d8c7f.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Oct 30, 2024

Unit Tests - Windows_x64_Release

520 tests   520 ✅  8s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit 54d8c7f.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Oct 30, 2024

Integration Tests - Windows_VS_x86_Release

0 tests   0 ✅  0s ⏱️
0 suites  0 💤
0 files    0 ❌

Results for commit 54d8c7f.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Oct 30, 2024

Unit Tests - Windows_VS_x86_Debug

498 tests   498 ✅  6s ⏱️
 69 suites    0 💤
  1 files      0 ❌

Results for commit 54d8c7f.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Oct 30, 2024

Integration Tests - Windows_x86_Debug

0 tests   0 ✅  0s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 54d8c7f.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Oct 30, 2024

Unit Tests - Windows_x86_Release

520 tests   520 ✅  8s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit 54d8c7f.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Oct 30, 2024

Unit Tests - Windows_VS_x64_Debug

498 tests   498 ✅  7s ⏱️
 69 suites    0 💤
  1 files      0 ❌

Results for commit 54d8c7f.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Oct 30, 2024

Unit Tests - Windows_x64_Debug

520 tests   520 ✅  14s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit 54d8c7f.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Oct 30, 2024

Unit Tests - Windows_VS_x64_Release

498 tests   498 ✅  5s ⏱️
 69 suites    0 💤
  1 files      0 ❌

Results for commit 54d8c7f.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Oct 30, 2024

Integration Tests - Windows_x86_Release

0 tests   0 ✅  0s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 54d8c7f.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Oct 30, 2024

Integration Tests - Windows_VS_x64_Debug

0 tests   0 ✅  0s ⏱️
0 suites  0 💤
0 files    0 ❌

Results for commit 54d8c7f.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Oct 30, 2024

Integration Tests - Windows_x64_Debug

0 tests   0 ✅  0s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 54d8c7f.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Oct 30, 2024

Integration Tests - Windows_VS_x64_Release

0 tests   0 ✅  0s ⏱️
0 suites  0 💤
0 files    0 ❌

Results for commit 54d8c7f.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Oct 30, 2024

Performance Tests - Windows_x86_Release

0 tests   0 ✅  0s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 54d8c7f.

♻️ This comment has been updated with latest results.

Copy link

Integration Tests - Windows_VS_x86_Debug

0 tests   0 ✅  0s ⏱️
0 suites  0 💤
0 files    0 ❌

Results for commit 54d8c7f.

Copy link

Integration Tests - Windows_x64_Release

0 tests   0 ✅  0s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 54d8c7f.

Copy link

Performance Tests - Windows_x64_Release

0 tests   0 ✅  0s ⏱️
1 suites  0 💤
1 files    0 ❌

Results for commit 54d8c7f.

@Automation51D Automation51D merged commit 37c1aaa into version/4.5 Oct 30, 2024
18 checks passed
@Automation51D Automation51D deleted the feature/extendable-evidence branch October 30, 2024 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants