xyarray.c 513 B

12345678910111213141516171819202122232425262728
  1. #include "xyarray.h"
  2. #include "util.h"
  3. struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size)
  4. {
  5. size_t row_size = ylen * entry_size;
  6. struct xyarray *xy = zalloc(sizeof(*xy) + xlen * row_size);
  7. if (xy != NULL) {
  8. xy->entry_size = entry_size;
  9. xy->row_size = row_size;
  10. xy->entries = xlen * ylen;
  11. }
  12. return xy;
  13. }
  14. void xyarray__reset(struct xyarray *xy)
  15. {
  16. size_t n = xy->entries * xy->entry_size;
  17. memset(xy->contents, 0, n);
  18. }
  19. void xyarray__delete(struct xyarray *xy)
  20. {
  21. free(xy);
  22. }