The R Project SVN R

Rev

Rev 10425 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 10425 Rev 11007
Line 952... Line 952...
952
 
952
 
953
/*
953
/*
954
  Quite heavily modified to make compile and remove redundant code,
954
  Quite heavily modified to make compile and remove redundant code,
955
  and to coalesce adjacent blocks.  This version does not always
955
  and to coalesce adjacent blocks.  This version does not always
956
  allocate contiguous space, and it cannot return space from other
956
  allocate contiguous space, and it cannot return space from other
957
  than the currently allocation block.
957
  than the current allocation block.
958
 
958
 
959
  BDR 2000-8-20.
959
  BDR 2000-8-20.
960
 */
960
 */
961
 
961
 
962
#ifdef WIN32
962
#ifdef WIN32
Line 975... Line 975...
975
#define TOP_MEMORY ((unsigned long)2*1024*1024*1024)
975
#define TOP_MEMORY ((unsigned long)2*1024*1024*1024)
976
 
976
 
977
static unsigned int gNextAddress = 0;
977
static unsigned int gNextAddress = 0;
978
static unsigned int gAddressBase = 0;
978
static unsigned int gAddressBase = 0;
979
static unsigned int gReservedSize = 0;
979
static unsigned int gReservedSize = 0;
-
 
980
static unsigned int totalAllocated = 0;
-
 
981
extern unsigned int R_max_memory;
980
 
982
 
981
static
983
static
982
int getpagesize(void)
984
int getpagesize(void)
983
{
985
{
984
    SYSTEM_INFO si;
986
    SYSTEM_INFO si;
Line 1028... Line 1030...
1028
{
1030
{
1029
    void *tmp;
1031
    void *tmp;
1030
    if (PageSize == 0) PageSize = getpagesize();
1032
    if (PageSize == 0) PageSize = getpagesize();
1031
 
1033
 
1032
    if (size > 0) {
1034
    if (size > 0) {
-
 
1035
	/* will this take us over the limit? */
-
 
1036
	if (totalAllocated + size > R_max_memory) 
-
 
1037
	    return (void*)-1;
-
 
1038
 
1033
	/* first check if request fits in reserved space, and if not
1039
	/* first check if request fits in reserved space, and if not
1034
	   try to reserve the address space (never unreserved) */
1040
	   try to reserve the address space (never unreserved) */
1035
	if (gAddressBase == 0) {
1041
	if (gAddressBase == 0) {
1036
	    gReservedSize = max (RESERVED_SIZE, AlignPage (size));
1042
	    gReservedSize = max (RESERVED_SIZE, AlignPage (size));
1037
	    gNextAddress = gAddressBase =
1043
	    gNextAddress = gAddressBase =
Line 1076... Line 1082...
1076
	    if (res == 0)
1082
	    if (res == 0)
1077
		return (void*)-1;
1083
		return (void*)-1;
1078
	}
1084
	}
1079
	tmp = (void*)gNextAddress;
1085
	tmp = (void*)gNextAddress;
1080
	gNextAddress = (unsigned int)tmp + size;
1086
	gNextAddress = (unsigned int)tmp + size;
-
 
1087
	totalAllocated += size + gNextAddress - AlignPage(gNextAddress);
1081
	return tmp;
1088
	return tmp;
1082
    } else if (size < 0) {
1089
    } else if (size < 0) {
1083
	unsigned int alignedGoal = AlignPage(gNextAddress + size);
1090
	unsigned int alignedGoal = AlignPage(gNextAddress + size);
1084
	/* Trim by decommiting the virtual memory */
1091
	/* Trim by decommiting the virtual memory */
1085
	if (alignedGoal >= gAddressBase)
1092
	if (alignedGoal >= gAddressBase)
1086
	{
1093
	{
1087
	    VirtualFree ((void*)alignedGoal, gNextAddress - alignedGoal,
1094
	    VirtualFree ((void*)alignedGoal, gNextAddress - alignedGoal,
1088
			 MEM_DECOMMIT);
1095
			 MEM_DECOMMIT);
1089
	    gNextAddress = gNextAddress + size;
1096
	    gNextAddress = gNextAddress + size;
-
 
1097
	    totalAllocated -= gNextAddress - alignedGoal;
1090
	    return (void*)gNextAddress;
1098
	    return (void*)gNextAddress;
1091
	}
1099
	}
1092
	else /* requested release of more than we have in this block */
1100
	else /* requested release of more than we have in this block */
1093
	{
1101
	{
1094
	    VirtualFree ((void*)gAddressBase, gNextAddress - gAddressBase,
1102
	    VirtualFree ((void*)gAddressBase, gNextAddress - gAddressBase,
1095
			 MEM_DECOMMIT);
1103
			 MEM_DECOMMIT);
1096
	    gNextAddress = gAddressBase;
1104
	    gNextAddress = gAddressBase;
-
 
1105
	    totalAllocated -= gNextAddress - gAddressBase;
1097
	    return (void*)-1;
1106
	    return (void*)-1;
1098
	}
1107
	}
1099
    } else { /* size = 0 */
1108
    } else { /* size = 0 */
1100
	return (void*)gNextAddress;
1109
	return (void*)gNextAddress;
1101
    }
1110
    }