Reputation: 2415
I would like to confirm, that these two code segment, which are identical apart from formatted, consume the same amount of memory.
Writing differently but should create the same amount of object instances and therefore the same amount of memory?
I'm looking for a link/article which 100% confirms this.
if (message.MailMessageAttachments != null && message.MailMessageAttachments.Count > 0)
{
foreach (var mailMessageAttachment in message.MailMessageAttachments)
{
mailMessage.Attachments.Add(
new Attachment(
new MemoryStream(
mailMessageAttachment.Attachment.ToArray()),
mailMessageAttachment.Filename + mailMessageAttachment.Extension));
}
}
and
if (message.MailMessageAttachments != null && message.MailMessageAttachments.Count > 0)
{
foreach (var mailMessageAttachment in message.MailMessageAttachments)
{
var btyeArray = mailMessageAttachment.Attachment.ToArray();
var attachmentMemoryStream = new MemoryStream(btyeArray);
var name = mailMessageAttachment.Filename + mailMessageAttachment.Extension;
var attachment = new Attachment(attachmentMemoryStream, name);
mailMessage.Attachments.Add(attachment);
}
}
Upvotes: 0
Views: 88
Reputation: 50190
"I would like to confirm, that these two code segment, which are identical apart from formatted, consume the same amount of memory."
These are not identical apart fro formatting. They are logically equivalent, but one stores intermediate values , the other does not.
If the question is - do they consume the same amount of memory at run time then the answer is probably yes. The storing of intermediate values that already exist probably doesnt add overhead. Many times people do this for debugging purposes.
Sounds like you are trying to win a code style argument with somebody
Upvotes: 1