Merge tag 'ntb-5.11' of git://github.com/jonmason/ntb
[linux/fpc-iii.git] / tools / lib / perf / xyarray.c
blobdcd901d154bb68bbe5d2cb8c64f9d55860709ca2
1 // SPDX-License-Identifier: GPL-2.0
2 #include <internal/xyarray.h>
3 #include <linux/zalloc.h>
4 #include <stdlib.h>
5 #include <string.h>
7 struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size)
9 size_t row_size = ylen * entry_size;
10 struct xyarray *xy = zalloc(sizeof(*xy) + xlen * row_size);
12 if (xy != NULL) {
13 xy->entry_size = entry_size;
14 xy->row_size = row_size;
15 xy->entries = xlen * ylen;
16 xy->max_x = xlen;
17 xy->max_y = ylen;
20 return xy;
23 void xyarray__reset(struct xyarray *xy)
25 size_t n = xy->entries * xy->entry_size;
27 memset(xy->contents, 0, n);
30 void xyarray__delete(struct xyarray *xy)
32 free(xy);