Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context Reallocate fails to allocate memory #7

Open
jarutis opened this issue Nov 7, 2014 · 0 comments
Open

Context Reallocate fails to allocate memory #7

jarutis opened this issue Nov 7, 2014 · 0 comments

Comments

@jarutis
Copy link

jarutis commented Nov 7, 2014

Hi,

I wanted to write an UDA which accumulates values and does some calculation in the final step. This works fine for very small samples. But `context->Reallocate' fails at arround 4MB. It returns a valid pointer but with allocated only 56 bytes.

Here is my Update code which accumulates values.

void DistributionUpdate(FunctionContext* context, const DoubleVal& input,
                        const IntVal& bins, StringVal* val) {
  if (input.is_null) return;
  DistributionStruct* dist = reinterpret_cast<DistributionStruct*>(val->ptr);

  if(dist->count >= dist->capacity) {
    dist->capacity += ELEMENT_ALLOCATION_SIZE;
    int new_size = val->len + dist->capacity * sizeof(double);
    val->ptr = context->Reallocate(val->ptr, new_size);
  }
  dist->elements[dist->count++] = input.val;
  dist->bins = bins.val;
}

If I debug this and check what is allocated versus what I expect to get allocated I get:

--TESTING NULL--
--TESTING 10 VALUE SAMPLE--
--TESTING NULL VALUE SAMPLE--
--TESTING COUNT < BINS--
--TESTING COUNT == BINS--
--TESTING 1000 UNSORTED VALUE SAMPLE--
--TESTING 1.000.000 VALUE SAMPLE--
[Reallocating old size:] Message: 800040
[Reallocating expected new size:] Message: 1600032
[Reallocating allocated new size:] Message: 1600040
[Reallocating old size:] Message: 1600040
[Reallocating expected new size:] Message: 2400032
[Reallocating allocated new size:] Message: 2400040
[Reallocating old size:] Message: 2400040
[Reallocating expected new size:] Message: 3200032
[Reallocating allocated new size:] Message: 3200040
[Reallocating old size:] Message: 3200040
[Reallocating expected new size:] Message: 4000032
[Reallocating allocated new size:] Message: 4000040
[Reallocating old size:] Message: 4000040
[Reallocating expected new size:] Message: 4800032
[Reallocating allocated new size:] Message: 56
Segmentation fault

Am I hitting some kind of limits, what am I missing here?

My full code is here:
https://gist.github.com/jarutis/7bb4e93a137607607a42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant