@@ -848,20 +848,22 @@ VOID WriteSetup(VOID)
848848 To be used for the main allocation of the sort buffers, and
849849 in a later stage for the function and subroutine sort buffers.
850850*/
851-
852851SORTING * AllocSort (LONG LargeSize , LONG SmallSize , LONG SmallEsize , LONG TermsInSmall ,
853852 int MaxPatches , int MaxFpatches , LONG IOsize )
854853{
855- LONG allocation ,longer ,terms2insmall ,sortsize ,longerp ;
854+ #ifndef SPLITALLOC
855+ LONG allocation ;
856+ #endif
857+ LONG longer ,terms2insmall ,sortsize ,longerp ;
856858 LONG IObuffersize = IOsize ;
857859 LONG IOtry ;
858860 SORTING * sort ;
859- int i = 0 , j = 0 ;
861+ int fname2Size = 0 , j = 0 ;
860862 char * s ;
861863 if ( AM .S0 != 0 ) {
862- s = FG .fname2 ; i = 0 ;
863- while ( * s ) { s ++ ; i ++ ; }
864- i += 16 ;
864+ s = FG .fname2 ; fname2Size = 0 ;
865+ while ( * s ) { s ++ ; fname2Size ++ ; }
866+ fname2Size += 16 ;
865867 }
866868 if ( MaxFpatches < 4 ) MaxFpatches = 4 ;
867869 longer = MaxPatches > MaxFpatches ? MaxPatches : MaxFpatches ;
@@ -897,10 +899,10 @@ SORTING *AllocSort(LONG LargeSize, LONG SmallSize, LONG SmallEsize, LONG TermsIn
897899 }
898900
899901 IOtry = ((LargeSize + SmallEsize )/MaxFpatches - 2 * AM .MaxTer )/sizeof (WORD )- COMPINC ;
900-
901902 if ( (LONG )(IObuffersize * sizeof (WORD )) < IOtry )
902903 IObuffersize = (IOtry + sizeof (WORD )- 1 )/sizeof (WORD );
903904
905+ #ifndef SPLITALLOC
904906 allocation =
905907 3 * sizeof (POSITION )* (LONG )longer /* Filepositions!! */
906908 + 2 * sizeof (WORD * )* longer
@@ -914,7 +916,7 @@ SORTING *AllocSort(LONG LargeSize, LONG SmallSize, LONG SmallEsize, LONG TermsIn
914916 + LargeSize
915917 + SmallEsize
916918 + sortsize
917- + IObuffersize * sizeof (WORD ) + i + 16 ;
919+ + IObuffersize * sizeof (WORD ) + fname2Size + 16 ;
918920 sort = (SORTING * )Malloc1 (allocation ,"sort buffers" );
919921
920922 sort -> LargeSize = LargeSize /sizeof (WORD );
@@ -931,11 +933,13 @@ SORTING *AllocSort(LONG LargeSize, LONG SmallSize, LONG SmallEsize, LONG TermsIn
931933 sort -> pStop = sort -> Patches + longer ;
932934 sort -> poina = sort -> pStop + longer ;
933935 sort -> poin2a = sort -> poina + longerp ;
936+
934937 sort -> fPatches = (POSITION * )(sort -> poin2a + longerp );
935938 sort -> fPatchesStop = sort -> fPatches + longer ;
936939 sort -> inPatches = sort -> fPatchesStop + longer ;
937940 sort -> tree = (WORD * )(sort -> inPatches + longer );
938941 sort -> used = sort -> tree + longerp ;
942+
939943#ifdef WITHZLIB
940944 sort -> fpcompressed = sort -> used + longerp ;
941945 sort -> fpincompressed = sort -> fpcompressed + longerp + 2 ;
@@ -944,13 +948,16 @@ SORTING *AllocSort(LONG LargeSize, LONG SmallSize, LONG SmallEsize, LONG TermsIn
944948#else
945949 sort -> ktoi = sort -> used + longerp ;
946950#endif
951+
947952 sort -> lBuffer = (WORD * )(sort -> ktoi + longerp + 2 );
948953 sort -> lTop = sort -> lBuffer + sort -> LargeSize ;
954+
949955 sort -> sBuffer = sort -> lTop ;
950956 if ( sort -> LargeSize == 0 ) { sort -> lBuffer = 0 ; sort -> lTop = 0 ; }
951957 sort -> sTop = sort -> sBuffer + sort -> SmallSize ;
952958 sort -> sTop2 = sort -> sBuffer + sort -> SmallEsize ;
953959 sort -> sHalf = sort -> sBuffer + (LONG )((sort -> SmallSize + sort -> SmallEsize )>>1 );
960+
954961 sort -> file .PObuffer = (WORD * )(sort -> sTop2 );
955962 sort -> file .POstop = sort -> file .PObuffer + IObuffersize ;
956963 sort -> file .POsize = IObuffersize * sizeof (WORD );
@@ -975,6 +982,77 @@ SORTING *AllocSort(LONG LargeSize, LONG SmallSize, LONG SmallEsize, LONG TermsIn
975982 sort -> cBufferSize = 0 ;
976983 sort -> f = 0 ;
977984 sort -> PolyWise = 0 ;
985+ #endif
986+
987+
988+ #ifdef SPLITALLOC
989+ // Separate buffers.
990+ sort = Malloc1 (sizeof (* sort ), "SPLITALLOC sorting struct" );
991+
992+ sort -> LargeSize = LargeSize /sizeof (WORD );
993+ sort -> SmallSize = SmallSize /sizeof (WORD );
994+ sort -> SmallEsize = SmallEsize /sizeof (WORD );
995+ sort -> MaxPatches = MaxPatches ;
996+ sort -> MaxFpatches = MaxFpatches ;
997+ sort -> TermsInSmall = TermsInSmall ;
998+ sort -> Terms2InSmall = terms2insmall ;
999+
1000+ sort -> sPointer = Malloc1 (sizeof (* (sort -> sPointer ))* terms2insmall , "SPLITALLOC sPointer" );
1001+ sort -> SplitScratch = Malloc1 (sizeof (* (sort -> SplitScratch ))* terms2insmall /2 , "SPLITALLOC SplitScratch" );
1002+ sort -> Patches = Malloc1 (sizeof (* (sort -> Patches ))* longer , "SPLITALLOC Patches" );
1003+ sort -> pStop = Malloc1 (sizeof (* (sort -> pStop ))* longer , "SPLITALLOC pStop" );
1004+ sort -> poina = Malloc1 (sizeof (* (sort -> poina ))* longerp , "SPLITALLOC poina" );
1005+ sort -> poin2a = Malloc1 (sizeof (* (sort -> poin2a ))* longerp , "SPLITALLOC poin2a" );
1006+
1007+ sort -> fPatches = Malloc1 (sizeof (* (sort -> fPatches ))* longer , "SPLITALLOC fPatches" );
1008+ sort -> fPatchesStop = Malloc1 (sizeof (* (sort -> fPatchesStop ))* longer , "SPLITALLOC fPatchesStop" );
1009+ sort -> inPatches = Malloc1 (sizeof (* (sort -> inPatches ))* longer , "SPLITALLOC inPatches" );
1010+ sort -> tree = Malloc1 (sizeof (* (sort -> tree ))* longerp , "SPLITALLOC tree" );
1011+ sort -> used = Malloc1 (sizeof (* (sort -> used ))* longerp , "SPLITALLOC used" );
1012+
1013+ #ifdef WITHZLIB
1014+ sort -> fpcompressed = Malloc1 (sizeof (* (sort -> fpcompressed ))* (longerp + 2 ), "SPLITALLOC fpcompressed" );
1015+ sort -> fpincompressed = Malloc1 (sizeof (* (sort -> fpincompressed ))* (longerp + 2 ), "SPLITALLOC fpincompressed" );
1016+ sort -> zsparray = 0 ;
1017+ #endif
1018+
1019+ sort -> ktoi = Malloc1 (sizeof (WORD )* (longerp + 2 ), "SPLITALLOC ktoi" );
1020+
1021+ // The combined Large buffer and Small buffer (+ extension) are used.
1022+ // They must be allocated together.
1023+ sort -> lBuffer = Malloc1 (LargeSize + SmallEsize , "SPLITALLOC lBuffer+sBuffer" );
1024+ sort -> lTop = sort -> lBuffer + sort -> LargeSize ;
1025+
1026+ sort -> sBuffer = sort -> lTop ;
1027+ if ( sort -> LargeSize == 0 ) { sort -> lBuffer = 0 ; sort -> lTop = 0 ; }
1028+ sort -> sTop = sort -> sBuffer + sort -> SmallSize ;
1029+ sort -> sTop2 = sort -> sBuffer + sort -> SmallEsize ;
1030+ sort -> sHalf = sort -> sBuffer + (LONG )((sort -> SmallSize + sort -> SmallEsize )>>1 );
1031+
1032+ sort -> file .PObuffer = Malloc1 (IObuffersize * sizeof (* (sort -> file .PObuffer ))+ fname2Size + 16 , "SPLITALLOC PObuffer" );
1033+ sort -> file .POstop = sort -> file .PObuffer + IObuffersize ;
1034+ sort -> file .POsize = IObuffersize * sizeof (WORD );
1035+ sort -> file .POfill = sort -> file .POfull = sort -> file .PObuffer ;
1036+ sort -> file .active = 0 ;
1037+ sort -> file .handle = -1 ;
1038+ PUTZERO (sort -> file .POposition );
1039+ #ifdef WITHPTHREADS
1040+ sort -> file .pthreadslock = dummylock ;
1041+ #endif
1042+ #ifdef WITHZLIB
1043+ sort -> file .ziosize = IObuffersize * sizeof (WORD );
1044+ sort -> file .ziobuffer = 0 ;
1045+ #endif
1046+ if ( AM .S0 != 0 ) {
1047+ sort -> file .name = (char * )(sort -> file .PObuffer + IObuffersize );
1048+ AllocSortFileName (sort );
1049+ }
1050+ else sort -> file .name = 0 ;
1051+ sort -> cBuffer = 0 ;
1052+ sort -> cBufferSize = 0 ;
1053+ sort -> f = 0 ;
1054+ sort -> PolyWise = 0 ;
1055+ #endif
9781056
9791057 return (sort );
9801058}
0 commit comments