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

Avoid malloc where unnecessary #211

Open
willGraham01 opened this issue Jan 9, 2023 · 0 comments
Open

Avoid malloc where unnecessary #211

willGraham01 opened this issue Jan 9, 2023 · 0 comments
Labels
housekeeping Code cleanup technical Technical and meta issues, not related to physics but infrastructure.

Comments

@willGraham01
Copy link
Collaborator

Running TDMS through Valgrind shows that we have a number of memory leaks from random malloc calls, and plhs never being unassigned. We also have a number of malloc'd blocks of size 0 bytes which we then write to 😬

We need to go through the codebase and check that we are not abusing the use of malloc: there are a number of cases where malloc is used when a scoped declaration would be sufficient; that is

int dims[2] = {1, 1};

rather than

int *dims = (int *) malloc(sizeof(int) * 2);
dims[0] = 1; dims[1] = 1;
free(dims);

In the case of variable-length arrays we can switch to std::vector:

std::vector<double> an(N);

as opposed to

double *an = (double *) malloc(sizeof(double) * N);
@willGraham01 willGraham01 changed the title Avoid malloc where necessary Avoid malloc where unnecessary Jan 9, 2023
@samcunliffe samcunliffe added technical Technical and meta issues, not related to physics but infrastructure. housekeeping Code cleanup labels Jan 10, 2023
@samcunliffe samcunliffe modified the milestones: v1.0, End of ARC project. May 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
housekeeping Code cleanup technical Technical and meta issues, not related to physics but infrastructure.
Projects
None yet
Development

No branches or pull requests

2 participants