You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
877 B
45 lines
877 B
#include <cow.hpp>
|
|
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
|
|
template<typename T = unsigned char>
|
|
void print_slice(Slice<T> memory)
|
|
{
|
|
printf("slice: { %p, %lu (%lu bytes) }\n", memory.area(), memory.size(), memory.size_bytes());
|
|
|
|
}
|
|
|
|
void write_fake(Cow& clone, const char* string)
|
|
{
|
|
strncpy(clone.area_as<char>(), string, clone.size_as<char>()-1);
|
|
}
|
|
|
|
void read_fake(const Cow& clone)
|
|
{
|
|
printf("read_fake: %s\n", clone.area_as<char>());
|
|
}
|
|
|
|
int main()
|
|
{
|
|
Cow real(4096);
|
|
|
|
printf("Created real: ");
|
|
print_slice(real.slice_wrap(-20, -10));
|
|
|
|
write_fake(real, "Hello world");
|
|
read_fake(real);
|
|
|
|
Cow::Fake clone = real;
|
|
printf("Fake size: %lu\n", clone.size());
|
|
printf("Fake ptr: %p\n", clone.area());
|
|
|
|
read_fake(clone);
|
|
write_fake(clone, "hello fake!");
|
|
read_fake(clone);
|
|
read_fake(real);
|
|
|
|
printf("First byte of: real = %x, fake = %x\n", real[0], clone[0]);
|
|
return 0;
|
|
}
|