Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information:CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
MyMacroCode = "CODE:"
MyMacroCode = MyMacroCode+"VERSION BUILD=5200814" + vbNewLine
MyMacroCode = MyMacroCode+"TAB T=1" + vbNewLine
MyMacroCode = MyMacroCode+"TAB CLOSEALLOTHERS" + vbNewLine
MyMacroCode = MyMacroCode+"URL GOTO=http://www.iopus.com" + vbNewLine
MyMacroCode = MyMacroCode+"URL GOTO=http://forum.iopus.com"
Does anyone have an example of creating the macro using PHP and constructing the macro inline as above?
Code: Select all
$str = 'CODE:'; $str = $str . 'line1' . "\r\n"; $str = $str . 'line2' . "\r\n";
Code: Select all
$str = 'CODE:'; $str .= 'line1' . "\r\n"; $str .= 'line2' . "\r\n";
Reason: replaced "\n" by "\r\n"
What you are doing with something like
Code: Select all
Dim myVar myVar = "Some text" myVar = myVar + " Extra Text" myVar = myVar + " And Some More Text" Response.Write ( myVar )
Declare a pointer called myVar
Reserve a 9 byte memory block and insert the Ascii values that represent the characters "Some text"
Point myVar to this memory block (assigning the value to the variable)
Line 3: -
Reserve a 20 byte block of memory
Copy the contents of the block of memory pointed to by myVar into the first 9 bytes of the 20 byte block
Reserve an 11 byte block of memory and put " Extra Text" in it
Copy the values in this memory to the 20 byte block, at the 10th Byte position onwards. (This is how the strings are concatenated)
Point myVar to this new 20 byte memory block containing "Some text Extra Text"
Release the memory blocks containing "Some text" and " Extra Text".
Line 4: -
Reserve a 39 Byte memory block
Copy the contents of the block of memory pointed to by myVar into the first 20 bytes of the 39 byte block
Reserve a 19 byte block of memory and put " And Some More Text" in it
Copy the values in this memory to the 39 byte block, at the 21st Byte position onwards. (Concatenating to the result of the previous concatenation)
Point myVar to this new 39 byte memory block containing "Some text Extra Text And Some More Text"
Release the memory blocks containing "Some text Extra Text" and " And Some More Text"
So with 1 assignment and 2 concatenations, you created & destroyed several memory blocks and copied values from memory block to memory block ("Some text" got assigned once and copied twice). All very memory and processor intensive. As you can also see, with every line of concatenation, more memory is reserved and more bytes are copied from block to block, to the point that just adding 1 more line can take up the equivalent processing and memory of all the previous lines combined, as you are creating buffers that contain all of the previous lines and the text to append, then copy them to an output memory block, the size of the 2 memory blocks you are concatenating. The memory usage and processing required, grow exponentially with the addition of each line of concatenation.
With a string builder, "Some text" doesn't get copied from memory block to memory block. It stays in the stringbuilder and isn't touched unless you've explicitly decided to remove it. Also It only gets copied once, when you output the stringbuilder to a string. It doesn't necessarily save the memory allocation, but it doesn't waste the memory and time it takes to create and destroy memory blocks. It only uses 1 memory block for each allocation. What it does is keep all the memory blocks, instead of the concatenation above. Finally, when you decide to access it as a whole string, it will copy the array of memory blocks to 1 big memory block once, creating a new string block and still leaving the array of memory blocks untouched unless you specifically request they be destroyed, or destroy the stringbuilder instance.
An example (With a 3rd party VBScript StringBuilder Class): -
Code: Select all
Dim myBuilder Set myBuilder = New StringBuilder myBuilder.Add "Some text" myBuilder.Add " Extra Text" myBuilder.Add " And Some More Text" Response.Write ( myBuilder.ToString() )
The simple concatenation created and destroyed memory blocks totaling 98 bytes for what resulted in a 39 byte string.
The StringBuilder used 39 Bytes for storage and created a 39 Byte output string (78 Bytes), with no overhead of copying block to block to block
Of course, the overhead of the StringBuilder object itself will have more than the 39 bytes used to store all the string snippets, because the StringBuilder object requires memory itself to exist, but the StringBuilder object can be reused and even if there was no memory saving (because it's used once to concatenate a few strings), there's always the performance improvement of copying memory blocks to the final output string, only once, instead of each concatenation.
It's Win - Win because it can save memory consumption, performs quicker, can manipulate the strings in different ways by having more methods than just ToString(), can combine the parts to create a different string, in combination with another StringBuilder instance. The string parts can be reused, sorted, manipulated without being part of 1 big string. Each myBuilder.Add line could contain just 1 word and you could sort them, search them or use the same string snippet twice in generating the output string, making memory use even more efficient. In other words, you gain flexibility as well as performance.
Code: Select all
Dim myBuilder Set myBuilder = New StringBuilder myBuilder.Add "the" 'Line 1 myBuilder.Add "quick" 'Line 2 myBuilder.Add "brown" 'Line 3 myBuilder.Add "fox" 'Line 4 myBuilder.Add "jumps" 'Line 5 myBuilder.Add "over" 'Line 6 myBuilder.Add "lazy" 'Line 7 myBuilder.Add "dogs" 'Line 8 'Just Create a String Response.Write ( myBuilder.ToString() ) 'Output: thequickbrownfoxjumpsoverlazydogs 'Format it (Sentence case "the" to "The", separate each word with a space and terminate with a period ".") Response.Write ( myBuilder.ToSentence() ) 'Output: The quick brown fox jumps over lazy dogs. 'Change the order of the words, reuse words (the) and format Response.Write ( myBuilder.ToSentenceOrder(1, 7, 4, 5, 6, 1, 2, 3, 8) ) 'Output: The lazy fox jumps over the quick brown dogs. 'Generate output other than a plain string Response.Write ( myBuilder.ToCsv() ) 'Output: "the","quick","brown","fox","jumps","over","lazy","dogs" 'Output to a file Response.Write ( myBuilder.ToSentenceFile("MyFile.txt") ) 'Output: Text file MyFile.txt containing: The quick brown fox jumps over lazy dogs. 'Sort ascending and separate with spaces Response.Write ( myBuilder.ToAscendingString() ) 'Output: brown dogs fox jumps lazy over quick the