-
Notifications
You must be signed in to change notification settings - Fork 539
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
Modify the memory allocation method of matd_t
to comply with ISO standards
#362
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add the compiler flags (add_compile_options(-Wall -Wextra -Wpedantic -Werror)
) to make sure that the warning does not appear again?
common/matd.c
Outdated
m->nrows = rows; | ||
m->ncols = cols; | ||
m->data = calloc(rows * cols, sizeof(TYPE)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has the potential to leek memory, if TYPE
gets redefined. We should either stick with double
wherever matd_t
is used, or replace all usages of double
with matd_t
by TYPE
macro.
39ec42e
to
a91a5a3
Compare
The original line 46 in |
Right. It was actually me who left this commented out (9959575). Probably a reminder that about unsolved issues. But now the checking seems to be too strict as the CI fails for clang with |
The original approach in I doubt this performance difference matters for the usage of matd within this project. Since most of the compute of apiltag detection is not within matrix calculations I imagine it won't make much difference. But it might be nice to just double check for a single image that this doesn't make a noticeable difference to compute speed |
a91a5a3
to
b25fc1e
Compare
b25fc1e
to
6d0f9e0
Compare
Alright, to pass the CI-CD, I temporarily commented out the The performance improvement brought by using
As you can see, the performance improvement brought by using flexible array memory is indeed noticeable, but it is at the static void matd(benchmark::State &state)
{
cv::Mat gray = cv::imread("1.png", cv::IMREAD_GRAYSCALE);
auto tf = tag25h9_create();
auto td = apriltag_detector_create();
// init
apriltag_detector_add_family(td, tf);
for (auto _ : state)
{
// format conversion
image_u8_t apriltag_img = {gray.cols, gray.rows, gray.cols, gray.data};
// detect
zarray_t *detections = apriltag_detector_detect(td, &apriltag_img);
// release
apriltag_detections_destroy(detections);
}
apriltag_detector_destroy(td);
tag25h9_destroy(tf);
}
BENCHMARK(matd)->Name("detect by (double *data)")->Iterations(100); And the result of this perf test are as follows:
In fact, I use this project as a There are two solutions to this problem.
|
Oh, by the way, the environment of this perf test are as follows.
|
The original way of writing
matd_t
waswhich does not conform to the ISO standard. For example, it will generate a warning in C++ compilers such as g++, with the following message:
Therefore, it was changed to use
double *
, and separate memory was allocated form
andm->data
. Additionally, resource release form->data
was added in thematd_destroy
function.