xyarray.c 603 B

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