Linux Perf
xyarray.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0
2 #include "xyarray.h"
3 #include "util.h"
4 #include <stdlib.h>
5 #include <string.h>
6 
7 struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size)
8 {
9  size_t row_size = ylen * entry_size;
10  struct xyarray *xy = zalloc(sizeof(*xy) + xlen * row_size);
11 
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;
18  }
19 
20  return xy;
21 }
22 
23 void xyarray__reset(struct xyarray *xy)
24 {
25  size_t n = xy->entries * xy->entry_size;
26 
27  memset(xy->contents, 0, n);
28 }
29 
30 void xyarray__delete(struct xyarray *xy)
31 {
32  free(xy);
33 }
void xyarray__delete(struct xyarray *xy)
Definition: xyarray.c:30
size_t row_size
Definition: xyarray.h:8
Definition: xyarray.h:7
size_t max_y
Definition: xyarray.h:12
x86 movsq based memset() in arch/x86/lib/memset_64.S") MEMSET_FN(memset_erms
struct xyarray * xyarray__new(int xlen, int ylen, size_t entry_size)
Definition: xyarray.c:7
char contents[]
Definition: xyarray.h:13
size_t entry_size
Definition: xyarray.h:9
size_t entries
Definition: xyarray.h:10
void free(void *)
size_t max_x
Definition: xyarray.h:11
void static void * zalloc(size_t size)
Definition: util.h:20
void xyarray__reset(struct xyarray *xy)
Definition: xyarray.c:23