URL:
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2008-11-19 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Clean and Fix tiled_image2d.
* garrigues/tiled_image2d/backend/mmap.hh,
* garrigues/tiled_image2d/tiled_image2d.cc,
* garrigues/tiled_image2d/tiled_image2d.hh: Use a lru cache of size 10
instead of 1500.
---
backend/mmap.hh | 7 +++++--
tiled_image2d.cc | 6 +++---
tiled_image2d.hh | 16 ++++++++++------
3 files changed, 18 insertions(+), 11 deletions(-)
Index: trunk/milena/sandbox/garrigues/tiled_image2d/backend/mmap.hh
===================================================================
--- trunk/milena/sandbox/garrigues/tiled_image2d/backend/mmap.hh (revision 2924)
+++ trunk/milena/sandbox/garrigues/tiled_image2d/backend/mmap.hh (revision 2925)
@@ -42,8 +42,8 @@
typedef Block block_type;
mmap_backend(int fd, unsigned n_blocks)
- : fd_(fd), size_(n_blocks) {
-
+ : fd_(fd), size_(n_blocks), n_loaded_(0) {
+ std::cout << "size: " << size_ << "blocks."
<< std::endl;
assert(Block::nbytes % getpagesize() == 0);
if (fd == -1) { perror("open"); exit(1); }
assert(fd_ != -1);
@@ -97,6 +97,7 @@
assert(n < size_);
Block *b = loaded_[n];
loaded_[n] = 0;
+ n_loaded_--;
if (munmap(b->bytes, Block::nbytes) == -1)
perror("munmap");
}
@@ -105,6 +106,7 @@
assert(n < size_);
Block *b = loaded_[n];
if (!b) {
+ n_loaded_++;
b = (Block*) mmap(0, Block::nbytes, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fd_, n *
Block::nbytes);
if (b == (void*)-1)
perror("mmap");
@@ -117,6 +119,7 @@
Block** loaded_;
int fd_;
unsigned size_;
+ int n_loaded_;
};
Index: trunk/milena/sandbox/garrigues/tiled_image2d/tiled_image2d.hh
===================================================================
--- trunk/milena/sandbox/garrigues/tiled_image2d/tiled_image2d.hh (revision 2924)
+++ trunk/milena/sandbox/garrigues/tiled_image2d/tiled_image2d.hh (revision 2925)
@@ -72,10 +72,10 @@
template <typename T>
struct data_< tiled_image2d<T> >
{
- typedef block<T, BLOCK_SIZE> block;
- typedef mmap_backend<block> backend;
- typedef lru_support<backend> support;
- typedef layout2d<BLOCK_SIDE, BLOCK_SIDE> layout;
+ typedef typename tiled_image2d<T>::block block;
+ typedef typename tiled_image2d<T>::backend backend;
+ typedef typename tiled_image2d<T>::support support;
+ typedef typename tiled_image2d<T>::layout layout;
data_(const box2d& b);
~data_();
@@ -154,9 +154,13 @@
/// Block type.
typedef block<T, BLOCK_SIZE> block;
+ //typedef block<T, 10> block;
+
+ /// Backend type.
+ typedef mmap_backend<block> backend;
/// Support type.
- typedef lru_support<mmap_backend<block> > support;
+ typedef lru_support<backend> support;
/// Layout type
typedef layout2d<BLOCK_SIDE, BLOCK_SIDE> layout;
/// Page type
@@ -245,7 +249,7 @@
support_(*new support(
*new backend( open("/tmp/milena_tiled.image", O_RDWR | O_CREAT |
O_TRUNC, 0664),
layout::image_layout::size(geom::nrows(b), geom::ncols(b))),
- 1500 // Fixme : size of lru cache.
+ 10 // Fixme : size of lru cache.
)
)
{
Index: trunk/milena/sandbox/garrigues/tiled_image2d/tiled_image2d.cc
===================================================================
--- trunk/milena/sandbox/garrigues/tiled_image2d/tiled_image2d.cc (revision 2924)
+++ trunk/milena/sandbox/garrigues/tiled_image2d/tiled_image2d.cc (revision 2925)
@@ -45,10 +45,10 @@
using namespace mln;
std::cout << "allocate the image." << std::endl;
- tiled_image2d<value::int_u8> ima(1024 * 1024, 1024 * 1.5);
+ tiled_image2d<value::int_u8> ima(30000, 30024);
std::cout << "fill the image." << std::endl;
debug::iota(ima);
- std::cout << "save the image." << std::endl;
- io::pgm::save(ima, "test.pgm");
+ //std::cout << "save the image." << std::endl;
+ //io::pgm::save(ima, "/tmp/test.pgm");
}