wsd See the demo-description: PARAMFILE1.ini [Section1] Param1=SomeParam1Value Param2=SomeParam2Value ... [Section2] Param1Sec2=SomeParam1Value Param2Sec2=SomeParam2Value ... PARAMFILE2.ini [Section1] Param1Sec1=SomeParam1Value ... Structure of these files are like the standard Windows ini-files. Application has a number of calls like this: char Param[128]; // Read Param1Sec1 value from file "PARAMFILE2.ini", section "Section1" ReadIniParameters("PARAMFILE2.ini", "Section1", "Param1Sec1", &Param); It is required to analyze different methods of creating the well-ordered data lists, which allow to provide the maximum access speed and to choose the most optimal. Main requirement is the speed, because 1) these functions are called quite often; 2) the application is written in C, but binaries are executed by something like virtual Forth machine. So functions like ReadIniParameters should be optimized for speed. Comments: Used programming language is C (ANSI). Time-consuming building of indexes for access to the configuration data is allowed on the initialization stage. Solution: I performed analysis of different algorithms for sorting and building index files. I decided to use CRC (CRC16) for indexes and to used “normalized” CRC value, in that way used the hashing method. One of the reasons of this choice is existence of the System CRC16 API function which can quickly calculate CRC16 of the data block by application request. ... Description of the index file creation: Summary number of parameters in all sections and all files is Nparams. When adding a new parameter from the INI file to the index file, following actions are taking place: char FullParamName[128]; // Create index for each parametr strcpy(FullParamName, FileName); //example:FullParamName="FILE1.INI" strcat(FullParamName, SectName); //example:FullParamName="FILE1.INISection4" strcat(FullParamName, ParamName); //example:"FILE1.INISection4Param8" // Calculate CRC from "Full Parametr name" tmpCRC= CalculateBlockCRC16(strlen(FullParamName), &FullParamName); // "Normalize" CRC for index file tmpCRC= tmpCRC/NParams; Each parameter is added to the index file based on the tmpCRC value. Index file consists of the Nparams records, each contains a set of references to the real values FileName+SectName+ParamName. In the common case there can be more than one refernces, because of the CRC16 collisions. In this case references will link to the different parameters and we need to compare them in the series: Index file ... CRC16_j-1/NParams CRC16_j/NParams -> link to (File+Sect+Param)1, (File+Sect+Param)2... ... When requesting the parameter’s value, ReadIniParameters function calculates the CRC16 from the (FileName+SectName+ParamName). Using the normalized value (CRC16/NParams) it quickly selects (using lseek) the small set of references to the real values of (FileName+SectName+ParamName) to check and compares them for the exact equality: typedef struct tag_tIndexRecord { long ParamLink; // Link to real FileName, Section, ParamName long NextIndexRec; // Link to next index (if exists) } tIndexRecord; int ReadIniParameters(char *FileName, char *Section, char *Param, char *Result) { WORD tmpCRC; char FullParamName[128]; int h; tIndexRecord InRec; tFileSecParam FileSecParam; // Calculate CRC from "Full Parameter name" strcpy(FullParamName, FileName); strcat(FullParamName, Section); strcat(FullParamName, Param); tmpCRC= CalculateBlockCRC16(strlen(FullParamName), &FullParamName); // "Normalize" CRC for index file tmpCRC= tmpCRC/NParams; // Read first index record if ( (h= open("fileind.ind", O_RDWR)) < 0 ) return(0); lseek(h, tmpCRC*sizeof(tIndexRecord), SEEK_SET); read(h, InRec, sizeof(tIndexRecord)); while ( InRec.ParamLink != -1 ) { lseek(h, ParamLink, SEEK_SET); read(h, FileSecParam, sizeof(tFileSecParam)); if ( !strcmp(FileSecParam.File, FileName) && ... This algorithm allows to get configuration parameters at a high speed, and it’s speed very slowly grows with increasing the summary number of parameters Nparams.
MrMiXeR http://www.wasm.ru/forum/viewtopic.php?pid=177683#p177683 http://www.wasm.ru/forum/viewtopic.php?pid=185513#p185513 http://www.wasm.ru/forum/viewtopic.php?pid=191873#p191873 http://www.wasm.ru/forum/viewtopic.php?pid=200017#p200017 http://www.wasm.ru/forum/viewtopic.php?pid=293371#p293371 http://www.wasm.ru/forum/viewtopic.php?pid=315635#p315635
Я всегда говорил, если хотите использовать switch, if-else, for, do-while, то программируйте на си, нечего асм загромждать этими конструкциями.
Microedition ну почему си можно и на асме ИМХО: первое что небходимо - принести в жертву некоторую часть быстродействия другими словами отдавать себе полный отчет в том что строящийся механизм не будет супер быстрым второе что нужно - разработать макос так чтоб вым было удобно мне например удобно так в 16 разрядных дос проектах Код (Text): ;=======[ STRUCTURE ]============================= Word_far\ STRUC Word_far_ID\ WORD ? Word_far_label\ DWORD ? Word_far\ ENDS ... ;;======[ MACRO ]================================= @Seek_by_WORD\ MACRO\ switch:req,\ segment_register:req,\ index_register:req,\ power:req LOCAL\ $next,\ $exit ;;---------------------------------------- $next: mov AX,WORD PTR\ segment_register:[index_register] IF @Fault cmp AX,@Fault ELSE or AX,AX ENDIF je $exit cmp AX,WORD PTR switch je $exit sub index_register,power jmp\ short $next $exit: ;;---------------------------------------- ENDM .... Word_far\ <@Fault,Method_Fx> Word_far\ <@Key_enter,Method_Enter> Word_far\ <@Key_tab,Main_Method_Tab> S0_Branches\ LABEL Word_far ... @Load_DS_SI\ S0_Branches-SIZE(Word_far) @Seek_by_WORD\ DX,DS,SI,<SIZE(Word_far)> stc call (Word_far PTR[SI])\ .Word_far_label