Why You Might Use StructCopy() Instead of Duplicate()
Wednesday, July 16th, 2008Over on Will Tomlinson’s blog there’s a piece about using structCopy() to create a copy of a struct and a note from Charlie Griefer cautioning that for Will’s example, he probably needed to use duplicate() instead. After discussing this will Will on IM, I figured it might be instructive to look at how structCopy() differs from duplicate() and why you might use it instead.
First off, let me say that the reason I think this causes confusion for a lot of CFers is that they don’t have a Computer Science background so they’ve not had the “Memory and Pointers 101″ course that makes this stuff a lot clearer. Hopefully, this blog post will help fill in some of the gaps.
Some basics. When you assign something to a variable in CFML, you are really doing two things: you are creating a label (the variable name) and you are allocating some memory to associate the label with the data. In particular, with structs, the struct itself exists in a block of memory (well, lots of connected blocks of memory) and then the variable “points to” the struct data.


