Memory optimize the 1d and 2d arrays

This commit is contained in:
2023-11-04 16:48:14 +01:00
parent d03ca99438
commit 5f4346d400

View File

@@ -21,7 +21,7 @@
*/
array_t *array_init(size_t size, size_t rows)
{
array_t *arr = calloc(sizeof(array_t) + (size * rows), 1);
array_t *arr = calloc(sizeof(array_t) + (size * rows - 1), 1);
if (!arr)
{
fprintf(stderr, "%s: Failed to allocate memory for array", __func__);
@@ -109,7 +109,7 @@ void array_free(array_t *arr)
*/
array_2d_t *array_2d_init(size_t size, size_t rows, size_t cols)
{
array_2d_t *arr = calloc(sizeof(array_2d_t) + (size * rows * cols), 1);
array_2d_t *arr = calloc(sizeof(array_2d_t), 1);
if (!arr)
{
fprintf(stderr, "%s: Failed to allocate memory for array", __func__);