]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - tools/perf/util/xyarray.c
UBUNTU: Ubuntu-4.13.0-45.50
[mirror_ubuntu-artful-kernel.git] / tools / perf / util / xyarray.c
1 #include "xyarray.h"
2 #include "util.h"
3 #include <stdlib.h>
4 #include <string.h>
5
6 struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size)
7 {
8 size_t row_size = ylen * entry_size;
9 struct xyarray *xy = zalloc(sizeof(*xy) + xlen * row_size);
10
11 if (xy != NULL) {
12 xy->entry_size = entry_size;
13 xy->row_size = row_size;
14 xy->entries = xlen * ylen;
15 xy->max_x = xlen;
16 xy->max_y = ylen;
17 }
18
19 return xy;
20 }
21
22 void xyarray__reset(struct xyarray *xy)
23 {
24 size_t n = xy->entries * xy->entry_size;
25
26 memset(xy->contents, 0, n);
27 }
28
29 void xyarray__delete(struct xyarray *xy)
30 {
31 free(xy);
32 }