News for hackers. Stuff that matters.
Re:C_std: Implementation of C++ standard libraries in C by properparity on Sunday January 28, 2024 @07:04AM (#39164876)

  Vector* vector_create(size_t itemSize) {
    Vector* vec = (Vector*)malloc(sizeof(Vector));
    // ...
    return vec;
  }
This just immediately strike me as poor code.

C is not java, you do not have to "new" up every little structure.

  void vector_init(Vector *v, size_t itemSize) {
    v->itemSize = itemSize;
    // ...
  }
Instantly cleaner, more efficient, less memory allocation/handling needed, lets the user control where the Vector is stored.
Re:C_std: Implementation of C++ standard libraries in C by gpderetta on Sunday January 28, 2024 @10:21AM (#39166583)
Assuming that vector is just a dataptr/size/capacity triplet, vector create can just return by value.
Re:C_std: Implementation of C++ standard libraries in C by pjmlp on Monday January 29, 2024 @02:11AM (#39173602)
The new operator in Java doesn't always heap allocate, it depends on the JIT and escape analysis, it might be stack/register allocated if proven safe to do so.