The R Project SVN R

Rev

Rev 26879 | Rev 26945 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 26879 Rev 26895
Line 879... Line 879...
879
*/
879
*/
880
#endif
880
#endif
881
 
881
 
882
/* R Specific declarations here */
882
/* R Specific declarations here */
883
 
883
 
884
/* The maximum via either sbrk or mmap */
-
 
885
unsigned long max_total_mem = 0;
-
 
886
 
-
 
887
extern unsigned int R_max_memory;
884
extern unsigned int R_max_memory;
-
 
885
extern int R_Is_Running;
-
 
886
void Rf_warning(const char *, ...);
888
 
887
 
889
/* reserve 256MB to ensure large contiguous space */
-
 
890
#define RESERVED_SIZE (256*1024*1024)
-
 
891
unsigned int R_reserved_size = RESERVED_SIZE;
-
 
892
 
888
 
893
/* ---------- description of public routines ------------ */
889
/* ---------- description of public routines ------------ */
894
 
890
 
895
/*
891
/*
896
  malloc(size_t n)
892
  malloc(size_t n)
Line 2978... Line 2974...
2978
        if (sum > (CHUNK_SIZE_T)(av->max_mmapped_mem)) 
2974
        if (sum > (CHUNK_SIZE_T)(av->max_mmapped_mem)) 
2979
          av->max_mmapped_mem = sum;
2975
          av->max_mmapped_mem = sum;
2980
        sum += av->sbrked_mem;
2976
        sum += av->sbrked_mem;
2981
        if (sum > (CHUNK_SIZE_T)(av->max_total_mem)) 
2977
        if (sum > (CHUNK_SIZE_T)(av->max_total_mem)) 
2982
          av->max_total_mem = sum;
2978
          av->max_total_mem = sum;
2983
		/* R Memory Statistics */
-
 
2984
		max_total_mem = av->max_total_mem;
-
 
2985
 
2979
 
2986
        check_chunk(p);
2980
        check_chunk(p);
2987
        
2981
        
2988
        return chunk2mem(p);
2982
        return chunk2mem(p);
2989
      }
2983
      }
Line 3274... Line 3268...
3274
      av->max_sbrked_mem = sum;
3268
      av->max_sbrked_mem = sum;
3275
    
3269
    
3276
    sum += av->mmapped_mem;
3270
    sum += av->mmapped_mem;
3277
    if (sum > (CHUNK_SIZE_T)(av->max_total_mem))
3271
    if (sum > (CHUNK_SIZE_T)(av->max_total_mem))
3278
      av->max_total_mem = sum;
3272
      av->max_total_mem = sum;
3279
	/* R Memory Statistics */
-
 
3280
	max_total_mem = av->max_total_mem;
-
 
3281
 
3273
 
3282
    check_malloc_state();
3274
    check_malloc_state();
3283
    
3275
    
3284
    /* finally, do the allocation */
3276
    /* finally, do the allocation */
3285
 
3277
 
Line 4197... Line 4189...
4197
      if (sum > (CHUNK_SIZE_T)(av->max_mmapped_mem)) 
4189
      if (sum > (CHUNK_SIZE_T)(av->max_mmapped_mem)) 
4198
        av->max_mmapped_mem = sum;
4190
        av->max_mmapped_mem = sum;
4199
      sum += av->sbrked_mem;
4191
      sum += av->sbrked_mem;
4200
      if (sum > (CHUNK_SIZE_T)(av->max_total_mem)) 
4192
      if (sum > (CHUNK_SIZE_T)(av->max_total_mem)) 
4201
        av->max_total_mem = sum;
4193
        av->max_total_mem = sum;
4202
	  /* R Memory Statistics */
-
 
4203
 	  max_total_mem = av->max_total_mem;
-
 
4204
      
4194
      
4205
      return chunk2mem(newp);
4195
      return chunk2mem(newp);
4206
    }
4196
    }
4207
#endif
4197
#endif
4208
 
4198
 
Line 5264... Line 5254...
5264
                }
5254
                }
5265
            } 
5255
            } 
5266
            /* Assert preconditions */
5256
            /* Assert preconditions */
5267
            assert ((unsigned) g_last->top_committed % g_pagesize == 0);
5257
            assert ((unsigned) g_last->top_committed % g_pagesize == 0);
5268
            assert (0 < commit_size && commit_size % g_pagesize == 0); {
5258
            assert (0 < commit_size && commit_size % g_pagesize == 0); {
-
 
5259
		mstate av = get_malloc_state();
-
 
5260
                void *base_committed;
-
 
5261
		if (av->sbrked_mem + av->mmapped_mem + size > R_max_memory) {
-
 
5262
		    if(R_Is_Running) 
-
 
5263
			Rf_warning("Reached total allocation of %dMb: see help(memory.size)", R_max_memory/1048576);
-
 
5264
		    goto sbrk_exit;
-
 
5265
		}
5269
                /* Commit this */
5266
                /* Commit this */
5270
                void *base_committed = VirtualAlloc (g_last->top_committed, commit_size, 
5267
                base_committed = VirtualAlloc (g_last->top_committed, 
-
 
5268
					       commit_size, 
5271
				    			                     MEM_COMMIT, PAGE_READWRITE);
5269
					       MEM_COMMIT, PAGE_READWRITE);
5272
                /* Check returned pointer for consistency */
5270
                /* Check returned pointer for consistency */
5273
                if (base_committed != g_last->top_committed)
5271
                if (base_committed != g_last->top_committed)
5274
                    goto sbrk_exit;
5272
                    goto sbrk_exit;
5275
                /* Assert postconditions */
5273
                /* Assert postconditions */
5276
                assert ((unsigned) base_committed % g_pagesize == 0);
5274
                assert ((unsigned) base_committed % g_pagesize == 0);
Line 5369... Line 5367...
5369
 
5367
 
5370
/* mmap for windows */
5368
/* mmap for windows */
5371
static void *mmap (void *ptr, long size, long prot, long type, long handle, long arg) {
5369
static void *mmap (void *ptr, long size, long prot, long type, long handle, long arg) {
5372
    static long g_pagesize;
5370
    static long g_pagesize;
5373
    static long g_regionsize;
5371
    static long g_regionsize;
-
 
5372
    mstate av = get_malloc_state();
5374
#ifdef TRACESB
5373
#ifdef TRACESB
5375
    printf ("mmap %ld\n", size);
5374
    printf ("mmap %ld\n", size);
5376
#endif
5375
#endif
5377
#if defined (USE_MALLOC_LOCK) && defined (NEEDED)
5376
#if defined (USE_MALLOC_LOCK) && defined (NEEDED)
5378
    /* Wait for spin lock */
5377
    /* Wait for spin lock */
Line 5385... Line 5384...
5385
        g_regionsize = getregionsize ();
5384
        g_regionsize = getregionsize ();
5386
    /* Assert preconditions */
5385
    /* Assert preconditions */
5387
    assert ((unsigned) ptr % g_regionsize == 0);
5386
    assert ((unsigned) ptr % g_regionsize == 0);
5388
    assert (size % g_pagesize == 0);
5387
    assert (size % g_pagesize == 0);
5389
    /* Allocate this */
5388
    /* Allocate this */
-
 
5389
    if (av->sbrked_mem + av->mmapped_mem + size > R_max_memory) {
-
 
5390
	if(R_Is_Running) 
-
 
5391
	    Rf_warning("Reached total allocation of %dMb: see help(memory.size)", R_max_memory/1048576);
-
 
5392
        ptr = (void *) MORECORE_FAILURE;
-
 
5393
	goto mmap_exit;
-
 
5394
    }
5390
    ptr = VirtualAlloc (ptr, size,
5395
    ptr = VirtualAlloc (ptr, size,
5391
					    MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE);
5396
			MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE);
5392
    if (! ptr) {
5397
    if (! ptr) {
5393
        ptr = (void *) MORECORE_FAILURE;
5398
        ptr = (void *) MORECORE_FAILURE;
5394
        goto mmap_exit;
5399
        goto mmap_exit;
5395
    }
5400
    }
5396
    /* Assert postconditions */
5401
    /* Assert postconditions */