Hey John,
2011/2/9 John Robson <[email protected]>
> "To process data of bytea type you need to retrieve the whole object
> from the database into a memory. Next, you may use WMemoryResource or
> save retrieved data to the file and use WFileResource." "I think it is
> reasonable to add WStreamResource into Wt -- the same as WFileResource
> but for working with std::istream. I consider it useful."
>
> "I believe it diserves a feature request and perhaps WFileResource could
> be refactored to be a specializiatino of a WStreamResource."
>
> I agree with these improvements. Today I did:
>
> std::vector<unsigned char> vectorUChar;
>
> std::ifstream file(uploadedFile.spoolFileName().c_str(), std::ios::in |
> std::ios::binary | std::ios::ate);
>
> if(file) {
> file.seekg(0, std::ios::end);
> std::ifstream::pos_type filesize = file.tellg();
> file.seekg(0, std::ios::beg);
> vectorUChar.resize(filesize);
> file.read((char*)(&vectorUChar[0]), filesize);
> file.close();
> std::remove(uploadedFile.spoolFileName().c_str());
> }
>
>
> I think UploadedFile could directly transform to std::vector<unsigned
> char>.
>
> I still did not create the image reading from DB to the browser, but I
> think using: WMemoryResource, then CREATE a File and then using
> WFileResource + WImage is a slow process and it consumes more CPU and
> disk space (why create a file that is in the db?).
>
> By listing dozens of images of the database to the browser would be
> better WImage (WResource) to read directly from the std::vector<unsigned
> char> (DB field bytea).
>
I believe that using WMemoryResource is reasonable for deploying
a static resource for a very often required content, e.g. logotype.
Because, obviously, you need to have enough amount of RAM for
using WMemoryResource for every image retrieved from the database.
I.e. WMemoryResource can be considered as a very fast
(intermediate) cache.
On the other hand, WFileResource can be considered as a
(intermediate) cache.
Reading large amount of data (image) via WResource from the field
of the database without saving it into a (intermediate) file can be a very
expensive, because the whole image will be retrieved from the database
on *each http request* (if you WResource construct a response
piecewise). So, if you are intended to use bytea, then using
WFileResource probably can be optimal solution.
To avoid creation of intermediate file each time consider to
implement a persistent cache.
>
> Regards,
> John
>
>
>
> ------------------------------------------------------------------------------
> The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
> Pinpoint memory and threading errors before they happen.
> Find and fix more than 250 security defects in the development cycle.
> Locate bottlenecks in serial and parallel code that limit performance.
> http://p.sf.net/sfu/intel-dev2devfeb
> _______________________________________________
> witty-interest mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/witty-interest
>
--
// Dmitriy.
------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest