Code Monkey home page Code Monkey logo

Comments (11)

darmar-lt avatar darmar-lt commented on May 19, 2024 1

Simply I am new on GitHub. But OK. I will try to prepare the pull request. However, it may take time until I understand the required steps.

By the way, I tried to compile qlibc under Windows using CMake. Without success. Is it possible to compile qlibc on Windows?

from qlibc.

wolkykim avatar wolkykim commented on May 19, 2024

No, the num represents the total number of objects stored in the vector. When the resize happen to be smaller size than the stored number of objects, it allows to keep the existing objects but will not allow to insert more objects there until num gets smaller than the max.

from qlibc.

darmar-lt avatar darmar-lt commented on May 19, 2024

It seems I do not understand how realloc works. In a documentation of realloc, I read: "The content of the memory block is preserved up to the lesser of the new and old sizes". I interpret this, that the existing objects outside of reallocated space are not preserved.

from qlibc.

wolkykim avatar wolkykim commented on May 19, 2024

from qlibc.

darmar-lt avatar darmar-lt commented on May 19, 2024

I have made a simple test case. Maybe it will help to understand the problem:

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "qlibc.h"

int main(void) {

    size_t i;
    size_t siz = sizeof(i);
    qvector_t *vec = qvector(10, siz, QVECTOR_RESIZE_LINEAR);

    for (i=0; i < 5; i++) {
        vec->addlast(vec, &i);
    }

    printf("Number of elements = %zu\n", vec->size(vec));
    for (i=0; i < vec->size(vec); i++) {
        printf("vec[%zu]=%zu\n", i, *(size_t*) vec->getat(vec, i, false));
    }

    vec->resize(vec, 3);
    printf("New number of elements = %zu\n", vec->size(vec));

    for (i=0; i < vec->size(vec); i++) {
        printf("vec[%zu]=%zu\n", i, *(size_t*) vec->getat(vec, i, false));
    }
    vec->free(vec);
    return 0;
}

On my PC, I have output (note, the last two lines are with wrong values):

Number of elements = 5
vec[0]=0
vec[1]=1
vec[2]=2
vec[3]=3
vec[4]=4
New number of elements = 5
vec[0]=0
vec[1]=1
vec[2]=2
vec[3]=65
vec[4]=0

from qlibc.

wolkykim avatar wolkykim commented on May 19, 2024

from qlibc.

darmar-lt avatar darmar-lt commented on May 19, 2024

Better not.

from qlibc.

wolkykim avatar wolkykim commented on May 19, 2024

from qlibc.

wolkykim avatar wolkykim commented on May 19, 2024

from qlibc.

levidurfee avatar levidurfee commented on May 19, 2024

@darmar-lt let us know if you need any help with the pull request :)

from qlibc.

wolkykim avatar wolkykim commented on May 19, 2024

not hearing back so long, closing

from qlibc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.