Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 1 | #include "xyarray.h" |
| 2 | #include "util.h" |
| 3 | |
| 4 | struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size) |
| 5 | { |
| 6 | size_t row_size = ylen * entry_size; |
| 7 | struct xyarray *xy = zalloc(sizeof(*xy) + xlen * row_size); |
| 8 | |
| 9 | if (xy != NULL) { |
| 10 | xy->entry_size = entry_size; |
| 11 | xy->row_size = row_size; |
Jiri Olsa | b45f65e | 2015-06-14 10:19:16 +0200 | [diff] [blame] | 12 | xy->entries = xlen * ylen; |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 13 | } |
| 14 | |
| 15 | return xy; |
| 16 | } |
| 17 | |
Jiri Olsa | b45f65e | 2015-06-14 10:19:16 +0200 | [diff] [blame] | 18 | void xyarray__reset(struct xyarray *xy) |
| 19 | { |
| 20 | size_t n = xy->entries * xy->entry_size; |
| 21 | |
| 22 | memset(xy->contents, 0, n); |
| 23 | } |
| 24 | |
Arnaldo Carvalho de Melo | 69aad6f | 2011-01-03 16:39:04 -0200 | [diff] [blame] | 25 | void xyarray__delete(struct xyarray *xy) |
| 26 | { |
| 27 | free(xy); |
| 28 | } |