⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ric_memoryallocationpkg_1.sbs

📁 基于Rhapsody平台的单片机8051的例子
💻 SBS
📖 第 1 页 / 共 4 页
字号:
							}
							- _isOrdered = 0;
							- _argumentDirection = In;
						}
					}
					- _returnType = { IHandle 
						- _m2Class = "IType";
						- _filename = "PredefinedTypes.sbs";
						- _subsystem = "PredefinedTypes";
						- _class = "";
						- _name = "void";
						- _id = GUID 1ae3fac8-89cb-11d2-b813-00104b3e6572;
					}
					- _abstract = 0;
					- _final = 0;
					- _concurrency = Sequential;
					- _protection = iPublic;
					- _static = 0;
					- _constant = 0;
					- _itsBody = { IBody 
						- _bodyData = "union RiCMemoryBlock* block;
assert( me != NULL );
assert( memory != NULL );

if ( me->freeList == NULL ) {
  me->freeList = memory;
} else {
  /* Find the last block */
  block = (union RiCMemoryBlock*)me->freeList;
  while ( block != NULL ) { 
    if ( block->next == NULL )
      break;
    block = block->next;
  }

  /* Return block to the freelist */
  block->next = (union RiCMemoryBlock*)memory;
}
block = (union RiCMemoryBlock*)memory;
block->next = NULL;";
					}
				}
				{ IPrimitiveOperation 
					- _id = GUID f54f9f04-1040-4d5e-ba31-f607fafdf6a2;
					- _name = "getMemory";
					- _description = { IDescription 
						- _text = "If a MemoryBlock is available then take it, else dynamically allocate the memory and use that.";
					}
					- _virtual = 0;
					- Args = { IRPYRawContainer 
						- size = 0;
					}
					- myReturnType = { IType 
						- _id = GUID 500d7865-4804-4720-a1a0-ee22d4381e22;
						- AssociationElements = { IRPYRawContainer 
							- size = 0;
						}
						- _declaration = "void*";
						- _kind = Language;
					}
					- _abstract = 0;
					- _final = 0;
					- _concurrency = Sequential;
					- _protection = iPublic;
					- _static = 0;
					- _constant = 0;
					- _itsBody = { IBody 
						- _bodyData = "union RiCMemoryBlock* block;
assert( me != NULL );
assert( me->blockSize > 0 && me->blockSize <= RIC_LARGE_BUFFER_SIZE );

if ( isEmpty(me) ) {
  /* Reallocate more memory */ 
  NOTIFY ( RIC_ALLOCATING_ANOTHER_MEMORYPOOL );
#ifdef NO_MALLOC
  assert ( FALSE );
#else
  block = (union RiCMemoryBlock*)((void*)malloc( me->blockSize ) );
#endif
  me->maxBlocks++; 
} else {
  /* Take a block off the freelist */
  block = (union RiCMemoryBlock*)me->freeList;
  me->freeList = block->next;
}
me->use++;
return block->memory;";
					}
				}
				{ IPrimitiveOperation 
					- _id = GUID d68e4a41-c9d0-4a76-8126-183996095681;
					- _name = "usage";
					- _description = { IDescription 
						- _text = "During debug, it is interesting to get an idea of how many buffers have been allocated. This operation will print for each pool, the maximum usage and the number of allocations.";
					}
					- _virtual = 0;
					- Args = { IRPYRawContainer 
						- size = 0;
					}
					- _returnType = { IHandle 
						- _m2Class = "IType";
						- _filename = "PredefinedTypes.sbs";
						- _subsystem = "PredefinedTypes";
						- _class = "";
						- _name = "void";
						- _id = GUID 1ae3fac8-89cb-11d2-b813-00104b3e6572;
					}
					- _abstract = 0;
					- _final = 0;
					- _concurrency = Sequential;
					- _protection = iPublic;
					- _static = 0;
					- _constant = 1;
					- _itsBody = { IBody 
						- _bodyData = "if ( me == NULL ) return;
#ifndef NO_PRINT
printf ( \"Pool %d Bytes called %d times maxBlocks %d\\n\", me->blockSize, me->use, me->maxBlocks );
#endif";
					}
				}
				{ IConstructor 
					- _id = GUID cb28253d-240d-4319-a176-dcdaaa5a66f1;
					- _virtual = 0;
					- Args = { IRPYRawContainer 
						- size = 3;
						- value = 
						{ IArgument 
							- _id = GUID c7dc31ab-3a25-4869-b1b3-fd5fee16df73;
							- _name = "initialNumber";
							- _defaultValue = "";
							- _typeOf = { IHandle 
								- _m2Class = "IType";
								- _filename = "PredefinedTypes.sbs";
								- _subsystem = "PredefinedTypes";
								- _class = "";
								- _name = "int";
								- _id = GUID 1ae3fac5-89cb-11d2-b813-00104b3e6572;
							}
							- _isOrdered = 0;
							- _argumentDirection = In;
						}
						{ IArgument 
							- _id = GUID 76557214-6b98-45ce-b496-83439a26b533;
							- _name = "aBlockSize";
							- _defaultValue = "";
							- _typeOf = { IHandle 
								- _m2Class = "IType";
								- _filename = "PredefinedTypes.sbs";
								- _subsystem = "PredefinedTypes";
								- _class = "";
								- _name = "int";
								- _id = GUID 1ae3fac5-89cb-11d2-b813-00104b3e6572;
							}
							- _isOrdered = 0;
							- _argumentDirection = In;
						}
						{ IArgument 
							- _id = GUID 5e2c12b4-e671-4b19-9117-cfd9b31674af;
							- _name = "memory";
							- _defaultValue = "";
							- myTypeOf = { IType 
								- _id = GUID adef9cac-985b-4957-8dba-bc027ac6dd77;
								- AssociationElements = { IRPYRawContainer 
									- size = 0;
								}
								- _declaration = "void*";
								- _kind = Language;
							}
							- _isOrdered = 0;
							- _argumentDirection = In;
						}
					}
					- _returnType = { IHandle 
						- _m2Class = "";
					}
					- _abstract = 0;
					- _final = 0;
					- _concurrency = Sequential;
					- _protection = iPublic;
					- _static = 0;
					- _constant = 0;
					- _itsBody = { IBody 
						- _bodyData = "union RiCMemoryBlock* currentBlock;
union RiCMemoryBlock* previousBlock;
int b;

currentBlock = (union RiCMemoryBlock*)memory;
previousBlock = NULL;  

/* Divide up allocated memory into blocks and add to the free list */
for ( b=0; b<initialNumber; b++ ) {
   me->freeList = currentBlock;
   /* Get top of current block to point to previous block */
   currentBlock->next = previousBlock;
   
   /* point to next block */
   previousBlock = currentBlock;
   
   currentBlock = (union RiCMemoryBlock*)((unsigned int)currentBlock + aBlockSize);
   me->maxBlocks++;    
}";
					}
					- _initializer = "me->blockSize = aBlockSize;
me->freeList = NULL;
me->use=0;
me->maxBlocks=0;";
				}
				{ IPrimitiveOperation 
					- _id = GUID 04ed127e-33ae-4da0-9942-b731ffb33e66;
					- _properties = { IPropertyContainer 
						- Subjects = { IRPYRawContainer 
							- size = 1;
							- value = 
							{ IPropertySubject 
								- _Name = "C_CG";
								- Metaclasses = { IRPYRawContainer 
									- size = 1;
									- value = 
									{ IPropertyMetaclass 
										- _Name = "Operation";
										- Properties = { IRPYRawContainer 
											- size = 1;
											- value = 
											{ IProperty 
												- _Name = "Inline";
												- _Value = "none";
												- _Type = Enum;
												- _ExtraTypeInfo = "none,in_header";
											}
										}
									}
								}
							}
						}
					}
					- _name = "isEmpty";
					- _virtual = 0;
					- Args = { IRPYRawContainer 
						- size = 0;
					}
					- _returnType = { IHandle 
						- _m2Class = "IType";
						- _filename = "PredefinedTypes.sbs";
						- _subsystem = "PredefinedTypes";
						- _class = "";
						- _name = "RiCBoolean";
						- _id = GUID b8644cfd-526b-4b0e-b2f1-f3f168e7f7cd;
					}
					- _abstract = 0;
					- _final = 0;
					- _concurrency = Sequential;
					- _protection = iPrivate;
					- _static = 0;
					- _constant = 1;
					- _itsBody = { IBody 
						- _bodyData = "if ( NULL == me->freeList )
  return TRUE;
else
  return FALSE;";
					}
				}
				{ IPrimitiveOperation 
					- _id = GUID 838127f8-386c-408d-97e9-7ec945276a7d;
					- _properties = { IPropertyContainer 
						- Subjects = { IRPYRawContainer 
							- size = 1;
							- value = 
							{ IPropertySubject 
								- _Name = "C_CG";
								- Metaclasses = { IRPYRawContainer 
									- size = 1;
									- value = 
									{ IPropertyMetaclass 
										- _Name = "Operation";
										- Properties = { IRPYRawContainer 
											- size = 5;
											- value = 
											{ IProperty 
												- _Name = "ImplementationEpilog";
												- _Value = "#endif
";
												- _Type = MultiLine;
											}
											{ IProperty 
												- _Name = "ImplementationProlog";
												- _Value = "#ifdef PRINT
";
												- _Type = MultiLine;
											}
											{ IProperty 
												- _Name = "Inline";
												- _Value = "none";
												- _Type = Enum;
												- _ExtraTypeInfo = "none,in_header";
											}
											{ IProperty 
												- _Name = "SpecificationEpilog";
												- _Value = "#endif 
";
												- _Type = MultiLine;
											}
											{ IProperty 
												- _Name = "SpecificationProlog";
												- _Value = "#ifdef PRINT
";
												- _Type = MultiLine;
											}
										}
									}
								}
							}
						}
					}
					- _name = "print";
					- _description = { IDescription 
						- _text = "Displays the list of memory in the free list.";
					}
					- _virtual = 0;
					- Args = { IRPYRawContainer 
						- size = 0;
					}
					- _returnType = { IHandle 
						- _m2Class = "IType";
						- _filename = "PredefinedTypes.sbs";
						- _subsystem = "PredefinedTypes";
						- _class = "";
						- _name = "void";
						- _id = GUID 1ae3fac8-89cb-11d2-b813-00104b3e6572;
					}
					- _abstract = 0;
					- _final = 0;
					- _concurrency = Sequential;
					- _protection = iPrivate;
					- _static = 0;
					- _constant = 1;
					- _itsBody = { IBody 
						- _bodyData = "/*
union RiCMemoryBlock* block;

block = me->freeList;
printf ( \"FreeList block size %d : %08x\", me->blockSize, block->memory );
while ( block->memory != NULL ) {
  block = block->next;
  printf ( \" %08x\", block->memory );
}
printf ( \"\\n\" );
*/";
					}
				}
				{ IDestructor 
					- _id = GUID 4d7c0164-cdb6-441b-9d62-9f9b1e331ffd;
					- _virtual = 0;
					- Args = { IRPYRawContainer 
						- size = 0;
					}
					- _returnType = { IHandle 
						- _m2Class = "";
					}
					- _abstract = 0;
					- _final = 0;
					- _concurrency = Sequential;
					- _protection = iPublic;
					- _static = 0;
					- _constant = 0;
					- _itsBody = { IBody 
						- _bodyData = "me->freeList = NULL;";
					}
				}
			}
			- TriggeredOperations = { IRPYRawContainer 
				- size = 0;
			}
			- Receptions = { IRPYRawContainer 
				- size = 0;
			}
			- ObjectLinks = { IRPYRawContainer 
				- size = 0;
			}
			- _classModifier = Unspecified;
		}
	}
	- Events = { IRPYRawContainer 
		- size = 0;
	}
	- Types = { IRPYRawContainer 
		- size = 5;
		- value = 
		{ IType 
			- _id = GUID 687ad498-9934-417d-ba68-c614c224e98e;
			- _name = "RIC_MEMORY_ALLOCATION";
			- _description = { IDescription 
				- _text = "All the various buffer sizes and initial numbers of them.
The smallest buffer size should be at least the size of an event. ie 16 bytes. ";
			}
			- AssociationElements = { IRPYRawContainer 
				- size = 0;
			}
			- _declaration = "typedef enum %s {
    RIC_SMALL_BUFFER_SIZE  = 32,
    RIC_MEDIUM_BUFFER_SIZE = 32,
    RIC_LARGE_BUFFER_SIZE  = 64,
    RIC_INITIAL_SMALL_BUFFERS  = 2,
    RIC_INITIAL_MEDIUM_BUFFERS = 1,
    RIC_INITIAL_LARGE_BUFFERS  = 0
    } %s;";
			- _kind = Language;
		}
		{ IType 
			- _id = GUID ea790975-bcb8-4244-b551-01a2efc7ed97;
			- _name = "RiCMediumMemoryBlock";
			- AssociationElements = { IRPYRawContainer 
				- size = 0;
			}
			- _declaration = "union %s {
  union %s*    next;
  unsigned int memory[RIC_MEDIUM_BUFFER_SIZE];
}";
			- _kind = Language;
		}
		{ IType 
			- _id = GUID d30050c9-d137-491e-866f-8f2ba0e5d8d0;
			- _name = "RiCSmallMemoryBlock";
			- AssociationElements = { IRPYRawContainer 
				- size = 0;
			}
			- _declaration = "union %s {
  union %s*    next;
  unsigned int memory[RIC_SMALL_BUFFER_SIZE];
}";
			- _kind = Language;
		}
		{ IType 
			- _id = GUID 8219df77-0d8e-4c8b-9c1d-c30a29c17e77;
			- _name = "RiCLargeMemoryBlock";
			- AssociationElements = { IRPYRawContainer 
				- size = 0;
			}
			- _declaration = "union %s {
  union %s*    next;
  unsigned int memory[RIC_LARGE_BUFFER_SIZE];
}";
			- _kind = Language;
		}
		{ IType 
			- _id = GUID c858776f-fbca-4022-8193-43ded87c9f9d;
			- _name = "RiCMemoryBlock";
			- AssociationElements = { IRPYRawContainer 
				- size = 0;
			}
			- _declaration = "union %s {
  union %s* next;
  unsigned char  memory[16];
}";
			- _kind = Language;
		}
	}
	- UseCases = { IRPYRawContainer 
		- size = 0;
	}
	- Actors = { IRPYRawContainer 
		- size = 0;
	}
	- _configurationRelatedTime = 1.15.2003::11:18:9;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -