Fix examples

This commit is contained in:
tevador 2019-10-09 19:49:54 +02:00
parent e0484dfb99
commit ebbe7696c7
2 changed files with 10 additions and 6 deletions

View File

@ -6,9 +6,10 @@ int main() {
const char myInput[] = "RandomX example input";
char hash[RANDOMX_HASH_SIZE];
randomx_cache *myCache = randomx_alloc_cache(RANDOMX_FLAG_DEFAULT);
randomx_flags flags = randomx_get_flags();
randomx_cache *myCache = randomx_alloc_cache(flags);
randomx_init_cache(myCache, &myKey, sizeof myKey);
randomx_vm *myMachine = randomx_create_vm(RANDOMX_FLAG_DEFAULT, myCache, NULL);
randomx_vm *myMachine = randomx_create_vm(flags, myCache, NULL);
randomx_calculate_hash(myMachine, &myInput, sizeof myInput, hash);

View File

@ -8,14 +8,17 @@ int main() {
const char myInput[] = "RandomX example input";
char hash[RANDOMX_HASH_SIZE];
randomx_cache *myCache = randomx_alloc_cache((randomx_flags)(RANDOMX_FLAG_JIT | RANDOMX_FLAG_LARGE_PAGES));
randomx_flags flags = randomx_get_flags();
flags |= RANDOMX_FLAG_LARGE_PAGES;
flags |= RANDOMX_FLAG_FULL_MEM;
randomx_cache *myCache = randomx_alloc_cache(flags);
if (myCache == nullptr) {
std::cout << "Cache allocation failed" << std::endl;
return 1;
}
randomx_init_cache(myCache, myKey, sizeof myKey);
randomx_dataset *myDataset = randomx_alloc_dataset(RANDOMX_FLAG_LARGE_PAGES);
randomx_dataset *myDataset = randomx_alloc_dataset(flags);
if (myDataset == nullptr) {
std::cout << "Dataset allocation failed" << std::endl;
return 1;
@ -28,7 +31,7 @@ int main() {
t2.join();
randomx_release_cache(myCache);
randomx_vm *myMachine = randomx_create_vm((randomx_flags)(RANDOMX_FLAG_FULL_MEM | RANDOMX_FLAG_JIT | RANDOMX_FLAG_HARD_AES | RANDOMX_FLAG_LARGE_PAGES), nullptr, myDataset);
randomx_vm *myMachine = randomx_create_vm(flags, nullptr, myDataset);
if (myMachine == nullptr) {
std::cout << "Failed to create a virtual machine" << std::endl;
return 1;
@ -40,7 +43,7 @@ int main() {
randomx_release_dataset(myDataset);
for (unsigned i = 0; i < RANDOMX_HASH_SIZE; ++i)
std::cout << std::hex << ((int)hash[i] & 0xff);
std::cout << std::hex << std::setw(2) << std::setfill('0') << ((int)hash[i] & 0xff);
std::cout << std::endl;