bool Data::loadFromFileOther(std::ifstream& input_file, std::string header_line, char seperator) { // Read header std::string header_token; std::stringstream header_line_stream(header_line); while (getline(header_line_stream, header_token, seperator)) { variable_names.push_back(header_token); } num_cols = variable_names.size(); num_cols_no_sparse = num_cols; // Read body reserveMemory(); bool error = false; std::string line; size_t row = 0; while (getline(input_file, line)) { std::string token_string; double token; std::stringstream line_stream(line); size_t column = 0; while (getline(line_stream, token_string, seperator)) { std::stringstream token_stream(token_string); token_stream >> token; set(column, row, token, error); ++column; } ++row; } num_rows = row; return error; }
bool Data::loadFromFileWhitespace(std::ifstream& input_file, std::string header_line) { // Read header std::string header_token; std::stringstream header_line_stream(header_line); while (header_line_stream >> header_token) { variable_names.push_back(header_token); } num_cols = variable_names.size(); num_cols_no_sparse = num_cols; // Read body reserveMemory(); bool error = false; std::string line; size_t row = 0; while (getline(input_file, line)) { double token; std::stringstream line_stream(line); size_t column = 0; while (line_stream >> token) { set(column, row, token, error); ++column; } if (column > num_cols) { throw std::runtime_error("Could not open input file. Too many columns in a row."); } else if (column < num_cols) { throw std::runtime_error("Could not open input file. Too few columns in a row. Are all values numeric?"); } ++row; } num_rows = row; return error; }
DataFloat::DataFloat(double* data_double, std::vector<std::string> variable_names, size_t num_rows, size_t num_cols) { this->variable_names = variable_names; this->num_rows = num_rows; this->num_cols = num_cols; this->num_cols_no_sparse = num_cols; reserveMemory(); for (size_t i = 0; i < num_cols; ++i) { for (size_t j = 0; j < num_rows; ++j) { data[i * num_rows + j] = (float) data_double[i * num_rows + j]; } } }
// Constructor copia CSR(CSR const &Mtx):n(Mtx.n),nnzMax(Mtx.nnzMax),nnz(Mtx.nnz) { reserveMemory(); // Copiamos los elementos de data y col for (int i = 0; i < nnz; ++i) { data[i] = Mtx.data[i]; col[i] = Mtx.col[i]; } // Copiamos los elementos de irow for (int i = 0; i < n; ++i) { irow[i] = Mtx.irow[i]; } };
void Loader::loadServiceCode(Task* task, CodeBytes* codeBytes, ServiceConfig* config) { std::list<Code*>* code = _parser->parse(codeBytes); if (reserveMemory(code)) { // Load code to reserved memory loadCodeToMemory(code); // Create new Task task->codeLocation = _memoryStart; task->pageCount = _endPageNr - _startPageNr + 2; if (config != NULL) { task->taskRegisters = config->getRegistersForMmuMapping(); } } _parser->deleteParsedCode(code); }
CSR(int m):n(m),nnzMax(m*30),nnz(0){reserveMemory();zeros();};
// Constructor de la clase Dense(int orden, std::string pname): Matrix(orden, orden, orden, pname){reserveMemory();zeros();};
bool MM_VirtualMemory::initialize(MM_EnvironmentBase* env, uintptr_t size, void* preferredAddress, void* ceiling, uintptr_t options, uint32_t memoryCategory) { OMRPORT_ACCESS_FROM_OMRPORT(env->getPortLibrary()); /* there is no memory taken already */ Assert_MM_true(NULL == _heapBase); uintptr_t allocateSize = size + _tailPadding; J9PortVmemParams params; omrvmem_vmem_params_init(¶ms); params.byteAmount = allocateSize; params.mode = _mode; params.options |= options; params.pageSize = _pageSize; params.pageFlags = _pageFlags; params.category = memoryCategory; if (NULL != preferredAddress) { params.startAddress = preferredAddress; params.endAddress = preferredAddress; } if ((NULL != ceiling) && (params.byteAmount <= (uintptr_t)ceiling)) { void* maxEndAddress = (void*)((uintptr_t)ceiling - params.byteAmount); /* * Temporary fix to cover problem in Port Library: * if direction is top down an allocation would be attempted from endAddress first regardless it page aligned or not * For unaligned case an allocation will succeed but not in requested pages * As far as this is only place in GC used endAddress add rounding here * (another case is handling of preferredAddress - we do not care) */ maxEndAddress = (void*)MM_Math::roundToFloor(_pageSize, (uintptr_t)maxEndAddress); if (params.endAddress > maxEndAddress) { params.endAddress = maxEndAddress; } } if (params.startAddress <= params.endAddress) { _heapBase = reserveMemory(¶ms); } if (NULL != _heapBase) { uintptr_t lastByte = (uintptr_t)_heapBase + (allocateSize - 1); /* If heap touches top of address range */ if (lastByte == HIGH_ADDRESS) { _heapTop = (void*)MM_Math::roundToFloor(_heapAlignment, ((uintptr_t)_baseAddress) + (allocateSize - _tailPadding - _heapAlignment)); } else { _heapTop = (void*)MM_Math::roundToFloor(_heapAlignment, ((uintptr_t)_baseAddress) + (allocateSize - _tailPadding)); } if ((_heapBase >= _heapTop) /* CMVC 45178: Need to catch the case where we aligned heapTop and heapBase to the same address and consider it an error. */ || ((NULL != ceiling) && (_heapTop > ceiling)) /* Check that memory we got is located below ceiling */ ) { freeMemory(); _heapBase = NULL; } } return NULL != _heapBase; }