PHP memcached:getDelayed&getMulti - 如何使用?(PHP memcached: getDelayed & getMulti - how to use?)
我最近想了一下如何在PHP应用程序中使用
getDelayed
和getMulti
,以及它们的区别。从阅读有关getDelayed的文档:
“该方法不会等待响应并立即返回。当您准备收集项目时,请调用Memcached :: fetch或Memcached :: fetchAll。”
因此,与
getMulti
不同,显然需要在键可用之前调用fetchAll。 但是,实际的memcached调用何时完成? 在fetchAll
或getDelayed
运行时?以示例更新:
$this->memcached->set('int', 99); $this->memcached->set('string', 'a simple string'); $this->memcached->set('array', array(11, 12)); $this->memcached->getDelayed(array('int')); $this->memcached->getDelayed(array('string')); $this->memcached->getDelayed(array('array')); print("<pre>".print_r( $this->memcached->fetchAll() )."</pre>"); // returns the array element only.
I have thought a bit recently about how to use
getDelayed
andgetMulti
in a PHP application, and their difference.From reading the documentation about getDelayed:
"The method does not wait for response and returns right away. When you are ready to collect the items, call either Memcached::fetch or Memcached::fetchAll."
So obviously there's a need to call fetchAll before having the keys available, unlike
getMulti
. But when is the actual memcached call being done? AtfetchAll
or whengetDelayed
is run?Updated with example:
$this->memcached->set('int', 99); $this->memcached->set('string', 'a simple string'); $this->memcached->set('array', array(11, 12)); $this->memcached->getDelayed(array('int')); $this->memcached->getDelayed(array('string')); $this->memcached->getDelayed(array('array')); print("<pre>".print_r( $this->memcached->fetchAll() )."</pre>"); // returns the array element only.
原文:https://stackoverflow.com/questions/2929054
最满意答案
不,它们并不总是等同,但在大多数流行的机器上,你会没事的。
calloc
将一个全零的模式写入分配的内存,但空指针值在某些机器上可能不是全位零(或者甚至只是某些机器上的某些类型)。查看C FAQ的Null Pointers部分,了解大量信息。
No, they are not always equivalent, but on most popular machines you'll be fine.
calloc
writes a bit pattern of all-zeros to the allocated memory, but the null pointer value might not be all-bits-zero on some machines (or even just for some types on some machines).Check out the Null Pointers section of the C FAQ for lots and lots of information.
相关问答
更多-
可能存在任何问题,例如: n_tot的值可能是垃圾。 您已经在已分配的块之外编写,并且这样做会破坏用于维护堆的数据结构。 There could be any number of problems, for example: The value of n_tot could be garbage. You have written outside of an allocated block, and in doing so you have destroyed data structures used to ...
-
你的问题的答案可能都归结为风格。 虽然你使用calloc是正确的,以确保分配的内存被清零,特别是在这样的情况下你没有在构造节点时分配所有字段,我不喜欢你依靠calloc设置0而不是具体分配上一个和下一个NULL。 你必须考虑其他人(甚至你)6个月后阅读这段代码。 通过不明确地分配prev和next到NULL,代码的意图稍微不那么明确。 像这样的东西: static struct ll_Node* ll_Node_new(void *data) { struct ll_Node *node = cal ...
-
由于您只有一个分配来创建整个devname数组,您只需要检查该数组是否为NULL ,并且只需要释放该数组。 当你通过devname ,每个条目实际上是一个struct Devices_names ,而不是一个指针,所以它不能与NULL进行比较或以任何有意义的方式释放。 在这种情况下,您将需要一个单独的变量来跟踪有多少个条目: for (i = 0; i < devname_count; i++) { printf("Device id --- [ %d ]\n", devname[i].id); ...
-
通常, malloc()和朋友不会仅因为您没有物理RAM而返回NULL 。 他们通常甚至不知道你有多少物理RAM,并且只是试图通过操作系统获得更多,通常使用mmap() (或brk() ,但这只是mmap()的包装器)。 mmap()也不会因为你没有物理RAM而返回失败,而是会尝试使用虚拟内存。 这在UNIX系统中很常见,并且通常不可能直接使用物理内存而不是虚拟内存。 OOM杀手只是Linux特定的实现,当虚拟内存无法处理对后备存储的需求时会发生什么。 让OOM杀手消失的一种方法是分配更多的交换空间(出于这 ...
-
编辑清楚 我想第一个和第二个是创建一个指向5结构设备的指针。 第三个是创建一个指向结构设备的指针? 第一个malloc(number * sizeof(*devices))将分配足够的内存来存储Device的number 。 正如其他人所提到的,您可以将此块视为一个Device数组。 你得到的指针将指向块的开头。 int number = 5; Device *ptr = malloc(number * sizeof(*ptr)); /* stuff */ free(ptr); 使用calloc的第二个做 ...
-
关于如何使用malloc()/ calloc()创建内存的误解(Misconception of how memory is created using malloc()/calloc())[2022-07-23]
看起来你正在比较苹果和橘子: 当你打印a[i] is at ...指针时,你会显示数组a的元素地址 然而,当你穿上内存布局时,你会在这些地址显示值 ,这些地址本身就是指针,所以整个画面看起来很混乱。 如果您在将calloc结果分配给它们之前在a[i]处打印值,则应该获得全零,因为calloc NULL不在内存中。 分配之后,您会看到指向每个a[i]处的6字节块的指针,这非常合理。 总结一下,当你用malloc和calloc分配内存时,你最初的理解是正确的:一旦分配了一块内存,它的地址*就保持不变。 *在具有 ... -
您可能有一个损坏的堆,例如某些内存已过早free (并且仍然重用),或者某些缓冲区溢出(或者像ptr[-3]这样的无效访问) 您应该使用valgrind来调试此类问题。 您也可以使用Boehm的保守垃圾收集器 。 你也可以用gdb手动捕获这些bug。 使用watch gdb命令并禁用地址空间布局随机化应该会有所帮助。 我还建议总是清除一个你有free -d的指针,所以在代码中用free(x), x=NULL替换free(x), x=NULL (所以如果x被错误地取消引用,你将立即得到一个SIGSEGV ) ...
-
问题出在这里: printf("%3d", **(arrayAscending + i)); 您正在递增指针指针。 根据我在这里看到的代码,它应该是以下内容: printf("%3d", *((*arrayAscending) + i))); 首先,您应该取消引用arrayAscending以获取指针integerArray值,并且只有在此增量之后才能使用索引。 你也可以这样写: printf("%3d",(*ayyarAscending)[i]); 但实际上更简单的只是使用索引: printf("% ...
-
calloc()和NULL(calloc() and NULL)[2023-02-23]
不,它们并不总是等同,但在大多数流行的机器上,你会没事的。 calloc将一个全零的模式写入分配的内存,但空指针值在某些机器上可能不是全位零(或者甚至只是某些机器上的某些类型)。 查看C FAQ的Null Pointers部分,了解大量信息。 No, they are not always equivalent, but on most popular machines you'll be fine. calloc writes a bit pattern of all-zeros to the alloc ... -
如何在C中使用calloc()?(How to use calloc() in C?)[2023-06-05]
您没有收到编译器错误,因为语法是正确的。 什么是不正确的是逻辑,你得到的是未定义的行为,因为你正在写入缓冲区末尾的内存。 为什么它是未定义的行为? 好吧,你没有分配那个内存,这意味着它不属于你 - 你正在进入一个被警告磁带封闭的区域。 考虑您的程序是否在缓冲区后直接使用内存。 你现在已经覆盖了那个内存,因为你超过了你的缓冲区。 考虑使用像这样的大小说明符: scanf("%9s", aString); 所以你不要超过你的缓冲区。 You don't get a compiler error because ...