Smart File Replacer
In this tutorial, you'll learn two ways to copy a smart object in Photoshop. Why look at two ways to do the same thing? Well, depending on which way you choose, you'll get very different results.
Both ways for copying a smart object are found under the Layer menu in the Menu Bar. The first is by choosing the New Layer via Copy command, and the second is by choosing New Smart Object via Copy. One of these commands will create an identical copy of your smart object that shares the same content as the original. And the other will create an entirely separate copy that's completely independent of the original. If you don't know the difference between them, you can get confusing and unexpected results. So, let's see how they work!
Vibration is the key radiation cannot flush it’s poisions over the key elements of the smart meter pleae look up harmonic sounding vis radiaion and smart meters sorry for typo’s ii just had some work done on my eyes i am trying to let the public know that this is the way to stop this whole situation of a killing monster. Batch file renamer that renames many files in a click. The app is intuitively simple, blazingly fast, and supports all major platforms: Windows, Mac, and Linux. Reviews are really important for me as for independent developer. If you like the app, please leave positive reviews.
I'll be using Photoshop CC but everything is fully compatible with Photoshop CS6. Let's get started!
Setting up the document
To see the difference between New Layer via Copy and New Smart Object via Copy, we'll start by converting a layer into a smart object. Then, we'll make two copies of the smart object, first using the New Layer via Copy command and then using New Smart Object via Copy. Once the copies are in place, we'll edit the smart objects and compare the results.
To follow along, you can use any image you like. I'll use this image that I downloaded from Adobe Stock.
If we look in the Layers panel, we see the image on a layer named 'Photo'. The Background layer, filled with white, sits below it:
Adding more canvas space
To make room for the copies, I'll add some extra canvas space to the document. To do that, I'll go up to the Image menu in the Menu Bar and I'll choose Canvas Size:
In the Canvas Size dialog box, I'll set the Width to 300 Percent and the Height to 100 Percent. I'll leave the Relative option unchecked. And in the Anchor grid, I'll leave the center square selected. Then I'll click OK to close the dialog box:
To fit the new canvas on the screen, I'll go up to the View menu and choose Fit on Screen:
And here's the result after adding more canvas. We now have room to place a copy of the image on either side of it:
Converting the layer to a smart object
To convert the image into a smart object, I'll make sure I have the 'Photo' layer selected in the Layers panel:
And then, in the Layer menu in the Menu Bar, I'll choose Smart Objects, and then Convert to Smart Object:
Back in the Layers panel, a smart object icon appears in the layer's preview thumbnail, telling us that the layer is now a smart object:
Renaming the smart object
Before we go any further, let's quickly rename the smart object so we'll know that this is the original. To rename it, I'll double-click on the name 'Photo' and I'll change it to 'Original'. Then I'll press Enter (Win) / Return (Mac) to accept it:
How to copy a smart object
So now that we've created an initial smart object, let's learn how to make a copy of it. There are two main ways to copy a smart object in Photoshop. One is by using the New Layer via Copy command, and the other is by using New Smart Object via Copy. Both are found under the Layer menu. Let's start with New Layer via Copy.
New Layer via Copy
With your smart object selected in the Layers panel, go up to the Layer menu, choose New, and then choose Layer via Copy. Note that there's also a keyboard shortcut you can use, which is Ctrl+J (Win) / Command+J (Mac). The New Layer via Copy command is normally used for making copies of layers, but it can also be used with smart objects:
In the Layers panel, a copy of the smart object is added above the original:
Moving the copy into place
To move the copy beside the original smart object in the document, I'll select Photoshop's Move Tool from the Toolbar:
Then, I'll press and hold my Shift key, and I'll click and drag the copy over to the left of the original. The Shift key limits the direction you can move, making it easier to drag straight across. We now have the original smart object in the center, and the copy made with the New Layer via Copy command on the left:
Renaming the first copy
Again to help us keep track of things, I'll rename this first copy of the smart object in the Layers panel from 'Original copy' to 'Layer via Copy':
New Smart Object via Copy
Next, let's make another copy of our smart object, this time using the New Smart Object via Copy command. In the Layers panel, I'll click on the original smart object to select it:
Then, in the Layer menu in the Menu Bar, I'll choose Smart Objects, and then New Smart Object via Copy:
A second copy of the smart object is added above the original:
Renaming the second copy
I'll rename the second copy 'Smart Object via Copy':
Changing the order of the smart objects
And then, just to keep things organized, I'll click and drag the 'Smart Object via Copy' version above the others:
I'll release my mouse button to drop it into place. And now we have the original smart object on the bottom, the New Layer via Copy version above it, and the copy made with New Smart Object via Copy at the top:
Moving the second copy into place
Finally, back in the document, I'll click with the Move Tool on the second copy and I'll drag it to the right of the original, holding my Shift key as I drag so it's easier to move straight across. We now have the original smart object in the center, the 'Layer via Copy' smart object on the left and the 'Smart Object via Copy' version on the right:
Comparing New Layer and New Smart Object via Copy
Now that we have our two copies in place, let's look at the difference between the New Layer via Copy command and New Smart Object via Copy. At the moment, both copies of our smart object look the same as the original. But there's a big difference between them, and the difference has to do with their content.
The copy we made using the New Layer via Copy command is a true copy of the original because both the original smart object and the copy share the same content. In other words, we're not really seeing a copy of the image. We're seeing the same image twice. If we edit the content inside the original smart object, the same change will appear in the copy. And changing the copy will display the same change in the original.
On the other hand, the copy we made using New Smart Object via Copy is a new smart object that's completely separate from the original, with its own independent copy of the content. Changing the original smart object will have no effect on the copy, and changing the copy will have no effect on the original.
Editing the original smart object
To show you what I mean, let's see what happens when we edit the smart objects. I covered how to edit smart objects in detail in the previous tutorial, so here, I'll go through it quickly. I'll start by making a change to the original smart object. To open it and view its contents, I'll double-click on the 'Original' smart object's thumbnail in the Layers panel:
The contents of the smart object open in a separate document:
Adding a Black & White adjustment layer
I'll convert the image in the original smart object to black and white. To do that, in the Layers panel, I'll click on the New Fill or Adjustment Layer icon at the bottom:
Then I'll choose Black & White from the list:
A Black & White adjustment layer appears above the image:
And in the document, we see the image now in black and white:
Saving and closing the document
To have the change appear in the main document, we need to save and close the smart object's document. To save it, go up to the File menu and choose Save:
And then to close the document, go back up to the File menu and choose Close:
One change, two results
Back in the main document, we see the result. The change I made to the original smart object in the center also appears in the copy on the left (the one made using the New Layer via Copy command). That's because both of them are sharing the same content, so changing one also changes the other. Yet the copy on the right, made with the New Smart Object via Copy command, is unaffected. And that's because New Smart Object via Copy created an entirely new smart object with its own separate version of the image:
Editing the 'New Layer via Copy' smart object
To see what we mean by two smart objects sharing the same content, I'll open the 'Layer via Copy' smart object on the left by double-clicking on its thumbnail in the Layers panel:
The contents again open in a separate document. But notice that it's actually the same document that we opened and made changes to earlier, with the same Black & White adjustment layer added in the Layers panel. Both the original smart object and the copy are displaying this same document:
Deleting the adjustment layer
I'll delete the Black & White adjustment layer by dragging it down onto the Trash Bin at the bottom of the Layers panel:
This restores the original color in the image:
Saving the changes
I'll save the change by going up to the File menu and choosing Save:
And then I'll close the smart object document by going up to the File menu and choosing Close:
Back in the main document, we again see the result. Even though this time, I made the change to the copy on the left, the original smart object in the center is also affected. Again, it's because they're both sharing that same smart object document:
Editing the 'New Smart Object via Copy' version
But let's see what happens if we edit the smart object on the right, the one made using the New Smart Object via Copy command. To open it, I'll double-click on its thumbnail in the Layers panel:
Again, the contents open in a separate document. But this time, it really is a separate document. It may look the same as the one we made changes to earlier, but because the New Smart Object via Copy command creates a brand new smart object, the contents here are completely separate from the original:
Adding a Gradient Map adjustment layer
To make a change, I'll try something different by adding a Gradient Map adjustment layer. I'll click the New Fill or Adjustment Layer icon at the bottom of the Layers panel:
And then I'll choose Gradient Map from the list:
A Gradient Map adjustment layer appears above the image:
In the Properties panel, I'll click on the small arrow to the right of the gradient swatch, and then I'll choose one of Photoshop's built-in gradients, like the Violet to Orange gradient, by double-clicking its thumbnail:
And finally, back in the Layers panel, I'll change the blend mode of the Gradient Map from Normal to Color:
And here's the result, with the gradient colors now blending in with the image:
Saving the changes
Again, I'll save my changes by going up to the File menu and choosing Save:
And then I'll close the smart object by going back up to the File menu and choosing Close:
And in the main document, we see that this time, only the smart object on the right is showing our changes. Again, that's because the New Smart Object via Copy command made an entirely new version of the smart object with no connection to the original:
Replacing the smart object contents
We've seen the difference between New Layer and New Smart Object via Copy when we edit a smart object. But the same is true when replacing a smart object's content. If we replace the content of the original smart object, any copies made using the New Layer via Copy command will also have their content replaced. But copies made with New Smart Object via Copy will be unaffected.
I'll select the original smart object in the Layers panel:
Then, to replace the image inside it with a different image, I'll go up to the Layer menu, then I'll choose Smart Objects, and then Replace Contents:
I'll navigate to the image I want to replace it with, and then I'll click on the image to select it, and click Place:
Photoshop instantly replaces the image in my original smart object with my new image. And because the copy on the left is sharing the same content as the original, it also had its content replaced. But because the smart object on the right is entirely separate, it's still showing its original content:
Which way to copy a smart object is best?
Now that we know the difference between New Layer via Copy and New Smart Object via copy, which one should you use? If you're making copies of a smart object to use in a layout or template, where you'll need any changes you make to the original to appear in the copies as well, you'll want to use the New Layer via Copy command. And, if you just want to make a new smart object from an existing one, with no connection between them, use New Smart Object via Copy instead.
And there we have it! That's how to copy a smart object in Photoshop! For more on smart objects, learn how to open and place images as smart objects, how to edit smart objects, how smart objects let us scale and resize images without losing quality, and how to apply filters as editable smart filters! You'll also find many more tutorials in our Photoshop Basics section!
In modern C++ programming, the Standard Library includes smart pointers, which are used to help ensure that programs are free of memory and resource leaks and are exception-safe.
Uses for smart pointers
Smart pointers are defined in the std
namespace in the <memory> header file. They are crucial to the RAII or Resource Acquisition Is Initialization programming idiom. The main goal of this idiom is to ensure that resource acquisition occurs at the same time that the object is initialized, so that all resources for the object are created and made ready in one line of code. In practical terms, the main principle of RAII is to give ownership of any heap-allocated resource—for example, dynamically-allocated memory or system object handles—to a stack-allocated object whose destructor contains the code to delete or free the resource and also any associated cleanup code.
In most cases, when you initialize a raw pointer or resource handle to point to an actual resource, pass the pointer to a smart pointer immediately. In modern C++, raw pointers are only used in small code blocks of limited scope, loops, or helper functions where performance is critical and there is no chance of confusion about ownership.
The following example compares a raw pointer declaration to a smart pointer declaration.
As shown in the example, a smart pointer is a class template that you declare on the stack, and initialize by using a raw pointer that points to a heap-allocated object. After the smart pointer is initialized, it owns the raw pointer. This means that the smart pointer is responsible for deleting the memory that the raw pointer specifies. The smart pointer destructor contains the call to delete, and because the smart pointer is declared on the stack, its destructor is invoked when the smart pointer goes out of scope, even if an exception is thrown somewhere further up the stack.
Access the encapsulated pointer by using the familiar pointer operators, ->
and *
, which the smart pointer class overloads to return the encapsulated raw pointer.
The C++ smart pointer idiom resembles object creation in languages such as C#: you create the object and then let the system take care of deleting it at the correct time. The difference is that no separate garbage collector runs in the background; memory is managed through the standard C++ scoping rules so that the runtime environment is faster and more efficient.
Important
Always create smart pointers on a separate line of code, never in a parameter list, so that a subtle resource leak won't occur due to certain parameter list allocation rules.
The following example shows how a unique_ptr
smart pointer type from the C++ Standard Library could be used to encapsulate a pointer to a large object.
The example demonstrates the following essential steps for using smart pointers.
Declare the smart pointer as an automatic (local) variable. (Do not use the
new
ormalloc
expression on the smart pointer itself.)In the type parameter, specify the pointed-to type of the encapsulated pointer.
Pass a raw pointer to a
new
-ed object in the smart pointer constructor. (Some utility functions or smart pointer constructors do this for you.)Use the overloaded
->
and*
operators to access the object.Let the smart pointer delete the object.
Smart pointers are designed to be as efficient as possible both in terms of memory and performance. For example, the only data member in unique_ptr
is the encapsulated pointer. This means that unique_ptr
is exactly the same size as that pointer, either four bytes or eight bytes. Accessing the encapsulated pointer by using the smart pointer overloaded * and -> operators is not significantly slower than accessing the raw pointers directly.
Smart pointers have their own member functions, which are accessed by using 'dot' notation. For example, some C++ Standard Library smart pointers have a reset member function that releases ownership of the pointer. This is useful when you want to free the memory owned by the smart pointer before the smart pointer goes out of scope, as shown in the following example.
Smart pointers usually provide a way to access their raw pointer directly. C++ Standard Library smart pointers have a get
member function for this purpose, and CComPtr
has a public p
class member. By providing direct access to the underlying pointer, you can use the smart pointer to manage memory in your own code and still pass the raw pointer to code that does not support smart pointers.
Kinds of smart pointers
The following section summarizes the different kinds of smart pointers that are available in the Windows programming environment and describes when to use them.
C++ Standard Library smart pointers
Use these smart pointers as a first choice for encapsulating pointers to plain old C++ objects (POCO).
unique_ptr
Allows exactly one owner of the underlying pointer. Use as the default choice for POCO unless you know for certain that you require ashared_ptr
. Can be moved to a new owner, but not copied or shared. Replacesauto_ptr
, which is deprecated. Compare toboost::scoped_ptr
.unique_ptr
is small and efficient; the size is one pointer and it supports rvalue references for fast insertion and retrieval from C++ Standard Library collections. Header file:<memory>
. For more information, see How to: Create and Use unique_ptr Instances and unique_ptr Class.shared_ptr
Reference-counted smart pointer. Use when you want to assign one raw pointer to multiple owners, for example, when you return a copy of a pointer from a container but want to keep the original. The raw pointer is not deleted until allshared_ptr
owners have gone out of scope or have otherwise given up ownership. The size is two pointers; one for the object and one for the shared control block that contains the reference count. Header file:<memory>
. For more information, see How to: Create and Use shared_ptr Instances and shared_ptr Class.weak_ptr
Special-case smart pointer for use in conjunction withshared_ptr
. Aweak_ptr
provides access to an object that is owned by one or moreshared_ptr
instances, but does not participate in reference counting. Use when you want to observe an object, but do not require it to remain alive. Required in some cases to break circular references betweenshared_ptr
instances. Header file:<memory>
. For more information, see How to: Create and Use weak_ptr Instances and weak_ptr Class.
Smart pointers for COM objects (classic Windows programming)
Smart File Replacer Free
When you work with COM objects, wrap the interface pointers in an appropriate smart pointer type. The Active Template Library (ATL) defines several smart pointers for various purposes. You can also use the _com_ptr_t
smart pointer type, which the compiler uses when it creates wrapper classes from .tlb files. It's the best choice when you do not want to include the ATL header files.
CComPtr Class
Use this unless you cannot use ATL. Performs reference counting by using the AddRef
and Release
methods. For more information, see How to: Create and Use CComPtr and CComQIPtr Instances.
CComQIPtr Class
Resembles CComPtr
but also provides simplified syntax for calling QueryInterface
on COM objects. For more information, see How to: Create and Use CComPtr and CComQIPtr Instances.
CComHeapPtr Class
Smart pointer to objects that use CoTaskMemFree
to free memory.
Wonder File
CComGITPtr Class
Smart pointer for interfaces that are obtained from the global interface table (GIT).
_com_ptr_t Class
Resembles CComQIPtr
in functionality but does not depend on ATL headers.
ATL smart pointers for POCO objects
In addition to smart pointers for COM objects, ATL also defines smart pointers, and collections of smart pointers, for plain old C++ objects (POCO). In classic Windows programming, these types are useful alternatives to the C++ Standard Library collections, especially when code portability is not required or when you do not want to mix the programming models of the C++ Standard Library and ATL.
CAutoPtr Class
Smart pointer that enforces unique ownership by transferring ownership on copy. Comparable to the deprecated std::auto_ptr
Class.
CHeapPtr Class
Smart pointer for objects that are allocated by using the C malloc function.
CAutoVectorPtr Class
Smart pointer for arrays that are allocated by using new[]
.
CAutoPtrArray Class
Class that encapsulates an array of CAutoPtr
elements.
CAutoPtrList Class
Class that encapsulates methods for manipulating a list of CAutoPtr
nodes.
See also
Pointers
C++ Language Reference
C++ Standard Library