X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fmemcached.hh;h=c6c3ef5e60f2a0e58e0f10b1bc2a27b38125ff71;hb=3f4d3e26db2dafabf270e964ba2be0dd72756c4d;hp=689a3bce068f21ff8421a33f264836d2f75f7b6f;hpb=bc9b4e408fbd3be5448136155870dcdbb8b65d58;p=m6w6%2Flibmemcached diff --git a/libmemcached/memcached.hh b/libmemcached/memcached.hh index 689a3bce..c6c3ef5e 100644 --- a/libmemcached/memcached.hh +++ b/libmemcached/memcached.hh @@ -82,24 +82,23 @@ public: bool mget(std::vector &keys) { + std::vector real_keys; + std::vector key_len; /* * Construct an array which will contain the length * of each of the strings in the input vector. Also, to * interface with the memcached C API, we need to convert * the vector of std::string's to a vector of char *. */ - size_t *key_len= static_cast(malloc(keys.size() * sizeof(size_t))); - if (key_len == NULL) - { - return false; - } - std::vector real_keys; + real_keys.reserve(keys.size()); + key_len.reserve(keys.size()); + std::vector::iterator it= keys.begin(); - int i= 0; + while (it != keys.end()) { real_keys.push_back(const_cast((*it).c_str())); - key_len[i++]= (*it).length(); + key_len.push_back((*it).length()); ++it; } @@ -109,8 +108,8 @@ public: */ if (!real_keys.empty()) { - memcached_return rc= memcached_mget(&memc, &real_keys[0], key_len, - static_cast(real_keys.size())); + memcached_return rc= memcached_mget(&memc, &real_keys[0], &key_len[0], + real_keys.size()); return (rc == MEMCACHED_SUCCESS); }