ignite-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Igor Sapego <isap...@gridgain.com>
Subject Re: C++ Distributed cache for caching files
Date Wed, 20 Apr 2016 16:10:11 GMT
Hello,

I can see that such kind of error can be caused if you don't have args[1]
filled.
Do you pass argument to the test when you run it?

Best Regards,
Igor

On Wed, Apr 20, 2016 at 5:34 PM, rajs123 <rajlaxmisah@gmail.com> wrote:

> Code:
>
> #include <iostream>
> #include <string>
> #include <fstream>
> #include <streambuf>
> #include <cerrno>
> #include <ctime>
> #include <chrono>
> #include "ignite/ignite.h"
> #include "ignite/ignition.h"
>
>
> using namespace ignite;
> using namespace cache;
> using namespace std;
>
> std::string get_file_contents(const char *filename)
> {
>                 std::ifstream in(filename, std::ios::in |
> std::ios::binary);
>                 if (in)
>                 {
>
> return(std::string((std::istreambuf_iterator<char>(in)),
> std::istreambuf_iterator<char>()));
>                 }
>                 throw(errno);
> }
>
> void PutFile(Cache<string, string>& cache, const char * file) {
>                 cout<<file&lt;&lt;endl;
>                 string key(file);
>                 string val = &quot;&quot;;
>                 auto start = std::chrono::high_resolution_clock::now();
>                 //val=get_file_contents(file);
>                 for (int i = 0; i &lt; 1000; i++)
>                                 val = val + &quot;aaaaa\n&quot;;
>                 auto elapsed = std::chrono::high_resolution_clock::now() -
> start;
>                 long long microseconds =
> std::chrono::duration_cast&lt;std::chrono::microseconds>(elapsed).count();
>                 cout<<val.length()&lt;&lt;&quot;
> &quot;&lt;&lt;microseconds&lt;&lt;&quot;!!&quot;&lt;&lt;endl;
>
>                 start = std::chrono::high_resolution_clock::now();
>                 cache.Put(key, val);
>                 elapsed = std::chrono::high_resolution_clock::now() -
> start;
>                 microseconds =
> std::chrono::duration_cast&lt;std::chrono::microseconds>(elapsed).count();
>                 cout<<"Put time: "<<" "<<key&lt;&lt;&quot;
> &quot;&lt;&lt;microseconds&lt;&lt;&quot;!!&quot;&lt;&lt;endl;
>
>                 start = std::chrono::high_resolution_clock::now();
>                 val = cache.Get(key);
>                 elapsed = std::chrono::high_resolution_clock::now() -
> start;
>                 std::ofstream out(&quot;output&quot;);
>                 out &lt;&lt; val;
>                 out.close();
>                 microseconds =
> std::chrono::duration_cast&lt;std::chrono::microseconds>(elapsed).count();
>                 cout<<"Get time: "<<microseconds&lt;&lt;&quot;
> &quot;&lt;&lt;val.length()&lt;&lt;&quot; !!&quot;&lt;&lt;endl;
>                 std::cout &lt;&lt; &quot;>>> Retrieved organization
> instance from cache: "
> << std::endl;
>
>                 /*auto start = std::chrono::high_resolution_clock::now();
>                   val = cache.Get(key);
>                   auto elapsed = std::chrono::high_resolution_clock::now()
> - start;
>                   long  long microseconds =
> std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count();
>                   cout<<"Get time: "<<microseconds&lt;&lt;&quot;
> &quot;&lt;&lt;val.length()&lt;&lt;&quot; !!&quot;&lt;&lt;endl;
>                   std::cout &lt;&lt; &quot;>>> Retrieved organization
> instance from cache:
> " << std::endl;*/
>                 //std::cout << val << std::endl;
>                 std::cout << std::endl;
> }
>
> int main(int argc, const char * argv[]) {
>
>                 IgniteConfiguration cfg;
>
>                 cfg.jvmInitMem = 512;
>                 cfg.jvmMaxMem = 1024*2;
>
>                 cfg.springCfgPath = "config/example-cache.xml";
>                 std::cout << std::endl;
>                 std::cout << ">>> Example started ..." << std::endl;
>                 try {
>                                 Ignite grid = Ignition::Start(cfg);
>                                 Cache<string, string> cache =
> grid.GetOrCreateCache<string,
> string>("example");
>                                 //                      Cache<string,
> string> cache = grid.GetCache<string,
> string>("example");
>
>                                 PutFile(cache, argv[1]);
>
>                 } catch (IgniteError& err) {
>                                 std::cout << "An error occurred: " <<
> err.GetText() << std::endl;
>                 }
>
>                 std::cout << std::endl;
>                 std::cout << ">>> Example finished, press any key to exit
> ..." <<
> std::endl;
>                 std::cout << std::endl;
>                 return 0;
> }
>
>
>
>
> --
> View this message in context:
> http://apache-ignite-users.70518.x6.nabble.com/C-Distributed-cache-for-caching-files-tp4158p4376.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Mime
View raw message