Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8954201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:16:03+00:00 2026-06-15T14:16:03+00:00

In my R package , the C code which implements the function allocates some

  • 0

In my R package , the C code which implements the function allocates some memory for usage.
What happens to this memory ?
Will it be under R’s GC’s radar or would it be a memory leak ?
If its under R’s garbage collection , will this memory be reclaimed back ?

I have a huge 5 GB of data to be allocated in R’s server process which is running as a server.
Here it would be a good idea if i can allocate this memory out of GC’s radar like we have outside heap memory allocation in Java.
So basically , can i allocate a huge amount of memory in my C code without R not disturbing that memory ?

I am planning to use malloc or calloc to allocate memory.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:16:05+00:00Added an answer on June 15, 2026 at 2:16 pm

    This is described fairly clearly in “Writing R Extensions” — one uses R variants of calloc() / malloc() that access the same pool of memory. That way R can gc() these things, and why you need PROTECT() annd UNPROTECT().

    6.1.2 User-controlled memory

    The other form of memory allocation is an interface to malloc, the
    interface providing R error handling. This memory lasts until freed
    by the user and is additional to the memory allocated for the R
    workspace.

    The interface functions are

     TYPE* Calloc(size_t N, TYPE)
     TYPE* Realloc(ANY *P, size_t N, TYPE)
     void Free(ANY *P)
    

    providing analogues of calloc, realloc and free. If there is an
    error during allocation it is handled by R, so if these routines
    return the memory has been successfully allocated or freed. Free
    will set the pointer P to NULL. (Some but not all versions of S do
    so.)

    Users should arrange to Free this memory when no longer needed,
    including on error or user interrupt. This can often be done most
    conveniently from an on.exit action in the calling R function – see
    pwilcox for an example.

    Do not assume that memory allocated by Calloc/Realloc comes
    from the same pool as used by malloc: in particular do not use
    free or strdup with it.

    These entry points need to be prefixed by R_ if
    STRICT_R_HEADERS has been defined.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have standard source code package under Linux which requires to run ./configure make
In the sun extended RMI tutorial, they have some interesting code which implements a
Consider this code: package Prova; import java.util.ArrayList; public class Prova { private ArrayList<String> people;
This is my code: package hello.project; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; import android.content.Context; import android.opengl.GLSurfaceView.Renderer;
I have this code: package com.powergroupbd.timer; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.CountDownTimer;
This is my MyTasteActivity code: package MyTaste; import android.app.Activity; import android.content.Context; import android.os.Bundle; import
Background: I recently completed a tic-tac-toe game in AS3, using some simple function-based code
Is there a package that contains Levenshtein distance counting function which is implemented as
I'm developing an application. This application contains 2 classes Discovery class which implements serializable
The R package caret provides a handy function createFolds , which returns a list

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.